Associating SharePoint 2013 Workflow to a SharePoint Online List and editing the XAML file

Sriram Varadarajan
 
Solution Architect
June 19, 2016
 
Rate this article
 
Views
10387

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

clip_image001

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

  1. In SharePoint Designer, go to the workflow whose XAML associations you would like to view
  2. Click on ‘Save as Template’
  3. This would create a .wsp file and save it to the Site Assets library in the site.
  4. Go to the Site Assets library in the browser and download the .wsp file
  5. Change the extension of the file from .wsp to .cab
  6. This would create a zipped file that you can extract and see the contents
  7. The zipped file would contain the workflow.xaml file and other associations
  8. 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.

https://blogs.msdn.microsoft.com/sharepointdesigner/2012/09/18/how-to-use-sharepoint-designer-2013s-visual-designer-to-move-workflows-between-sites/

Using CSOM

Refer: https://howtodowithsharepoint.wordpress.com/2015/07/09/sharepoint-2013-how-to-add-workflow-association-to-the-list-using-workflow-subscription-service/

 [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()

Author Info

Sriram Varadarajan
 
Solution Architect
 
Rate this article
 
Sriram is a Technology Evangelist with 15+ years experience in Microsoft Technologies. He is an enterprise architect working for large pharmaceutical organization which has presence globally with largest Microsoft implementation ...read more
 

Leave a comment