Though our major goal is to associate the Work Flow to a SharePoint Online List but the sub set of this would be to edit the XAML file. In this blog, first I will take you through how to edit/open the XAML file and next part would be associating the Work Flow.
Scenario
I have developed a Workflow in my Test site and I wanted that workflow to be associated to a different list under a different site, but when I opened my target site using designer I couldn’t find the Workflow folder under All Files. For me to change the association I should be able to edit the XAML file
So, why is that my site missing that folder????
Here are the answers to that question
· ‘Workflows’ folder under ‘All Files’ is only for SharePoint 2010 workflows and would be visible if you have SharePoint 2010 workflows in your site
· For SharePoint 2013 workflows, the XAML associations are present in the hidden list ‘Wfsvc’
· After I created a 2010 workflow, I was able to see the ‘Workflows’ folder
How to see the XAML file
Option 1
To see the XAML associations for SharePoint 2013 workflows, unhide the ‘wfsvc’ library using PS
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$url="https://XXX.sharepoint.com/sites/test1234" #URL of the site
$password=Read-Host -Prompt "Enter Password" -AsSecureString
$credentials=New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("USER ID",$password) #user name of an admin account within “”
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$ctx.Credentials=$credentials
$web=$ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$listcoll=$web.Lists
$ctx.Load($listcoll)
$ctx.ExecuteQuery()
$list=$listcoll.GetByTitle('wfsvc')
$ctx.Load($list)
$ctx.ExecuteQuery()
$list.SchemaXml
$list.Hidden=$false
$list.Update()
Try opening the list using OPEN WITH EXPLORER make sure to read this article before you do that https://support.microsoft.com/en-in/kb/2629108
Open the XAML file
Option 2
- In SharePoint Designer, go to the workflow whose XAML associations you would like to view
- Click on ‘Save as Template’
- This would create a .wsp file and save it to the Site Assets library in the site.
- Go to the Site Assets library in the browser and download the .wsp file
- Change the extension of the file from .wsp to .cab
- This would create a zipped file that you can extract and see the contents
- The zipped file would contain the workflow.xaml file and other associations
- You can view and the xaml file
But these options would still not help you to associate your workflow, here are the options as on today to achieve it.
Using CSOM
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadFile("C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.WorkflowServices.dll")
$url="" #URL of the site
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$password=Read-Host -Prompt "Enter your pwd:" -AsSecureString
$cred=New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("",$password) #Username
$ctx.Credentials=$cred
$web=$ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$listcoll=$web.Lists
$ctx.Load($listcoll)
$ctx.ExecuteQuery()
$listcoll | select Title,id
$list=$listcoll.GetByTitle("") #Title of the list where the workflow is currently added
$ctx.Load($list)
$ctx.ExecuteQuery()
$fields=$list.Fields
$ctx.Load($fields)
$ctx.ExecuteQuery()
$fields | select title,id
$wffield=$fields.GetById('') #id of the field that has the workflow name
$ctx.Load($wffield)
$ctx.ExecuteQuery()
$list2=$listcoll.GetById('') #id of the list where you need to move the workflow to
$ctx.Load($list2)
$ctx.ExecuteQuery()
$fieldcoll=$list2.Fields
$ctx.Load($fieldcoll)
$ctx.ExecuteQuery()
$fieldcoll.Add($wffield)
$ctx.Load($fieldcoll)
$ctx.ExecuteQuery()
$wfsm=New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($ctx,$web)
$ctx.Load($wfsm)
$ctx.ExecuteQuery()
$wss=$wfsm.GetWorkflowSubscriptionService()
$ctx.Load($wss)
$ctx.ExecuteQuery()
$listsub=$wss.EnumerateSubscriptionsByList('') #list id of the list which has the workflow, $list
$ctx.Load($listsub)
$ctx.ExecuteQuery()
$wf=$listsub[0]
$ctx.Load($wf)
$ctx.ExecuteQuery()
$wf.EventSourceId='' #id of the list where you are moving the workflow to
$ctx.Load($wf)
$ctx.ExecuteQuery()
$wss.PublishSubscriptionForList($wf,$list2.Id)
$ctx.ExecuteQuery()
Leave a comment