I've created a SharePoint 2013 Reusable Workflow using SharePoint Designer. It is based on a content type called Functional Design:
If I publish that workflow to the site collection where it was developed - it works perfectly. If I package it (Save as Template), upload as a Solution (.wsp) in a different site collection - it doesn't work - SharePoint doesn't pick up the fields.
The way I do it is:
- I develop the workflow in a site collection called "Site 1". There is a feature activated in that site collection which deploys a content type called "Functional Design" (which the workflow is based on);
- Save workflow as a template
- Activate features (for the Functional Design content type) in another site collection called Site 2. Field internal names and content type IDs are identical in both site collections.
- Upload saved workflow as a .wsp to the Solutions gallery and activate the feature which enables to use this workflow.
- Create a list which has a sigle Functional Design content type in it. Same list template + content type used to create the workflow in Site 1.
- Associate the workflow with the the list created previously. I use the following PowerShell script:
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($Web) $defSevice = $wfm.GetWorkflowDeploymentService() $wfDefs = $defSevice.EnumerateDefinitions($false) $wfDef = $wfDefs | where {$_.DisplayName -eq $WorkflowName} $wfsubService = $wfm.GetWorkflowSubscriptionService() $sub = New-object Microsoft.SharePoint.WorkflowServices.WorkflowSubscription $sub.DefinitionId = $wfDef.Id $sub.Enabled = $true $sub.Name = $wfDef.DisplayName $startOptions = New-Object "System.Collections.ObjectModel.Collection[System.String]" $startOptions.Add("WorkflowStart") $sub.EventTypes = $startOptions $sub.SetProperty("HistoryListId", $HistoryListId) $sub.SetProperty("TaskListId", $TaskListId) $wfSubService.PublishSubscriptionForList($sub, $ApprovalListId);
I am pretty sure that the workflow is associated successfully. If I run EnumerateSubscriptionsByList
, I can see that the workflow is attached to the list:
If I open the workflow in SharePoint Designer I can see that the fields for the Current Item are missing:
And I can't select them anymore:
While the workflow on Site 1 still has them:
I assume that the workflow doesn't pick up the content type correctly in the new site collection. Does anyone have any thoughts why this goes wrong?