1

I've created a SharePoint 2013 Reusable Workflow using SharePoint Designer. It is based on a content type called Functional Design:

enter image description here

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:

  1. 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);
  2. Save workflow as a template
  3. 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.
  4. Upload saved workflow as a .wsp to the Solutions gallery and activate the feature which enables to use this workflow.
  5. 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.
  6. 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: enter image description here

  1. If I try to run it, an error appears on the Workflow Status page: enter image description here

If I open the workflow in SharePoint Designer I can see that the fields for the Current Item are missing:

enter image description here

And I can't select them anymore:

enter image description here

While the workflow on Site 1 still has them:

enter image description here

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?

0

Turned out that when associating workflow (publishing subscription) with a list it is not enough to use $wfSubService.PublishSubscriptionForList($sub, $ApprovalListId); - you need to explicitly set list id on workflow definition. I edited the PowerShell script and added the following lines:

$wfDef.RestrictToType = "List"
$wfDef.RestrictToScope = $ApprovalListId
$defSevice.SaveDefinition($wfDef);

Which specifies that that workflow definition is restricted to my custom list. Now the custom columns are picked up correctly on a new site collection. Complete PowerShell script looks like that:

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($Web)
$defSevice = $wfm.GetWorkflowDeploymentService()
$wfDefs = $defSevice.EnumerateDefinitions($false)
$wfDef = $wfDefs | where {$_.DisplayName -eq $WorkflowName}

$wfDef.RestrictToType = "List"
$wfDef.RestrictToScope = $ApprovalListId
$defSevice.SaveDefinition($wfDef);

$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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.