Sunday 24 September 2017

SPWorkflowAssociation object lost link to Task List or History List

Recently I ran into a issue, where the workflow association object lost the link to Task List. Due to this the Workflow stopped working and status was "error" in the workflow status.

On further investigation I found that the task list attached to the workflow association had been deleted and re-created. And the workflow association was still referencing the old task list.
In our case the "Workflow Association Form" was hidden for some reason. Hence, we had to debug and fix this using "Power-Shell".

SPList.WorkflowAssociations gives handle of all the associations to a particular list.
The individual workflow association object has TaskListId and HistoryListId, these properties show the GUID of the respective lists.

-------------------------------------------------------------------------
Below script will help update these entries and fix the issue.
-------------------------------------------------------------------------

for($i = 0; $i  -lt  $list.WorkflowAssociations.Count; $i++)
{
   $wfAssocObj = $list.WorkflowAssociations[$i];
   if($wfAssocObj.TaskListId -ne $taskList.Id)
   {
         Write-Host "Association: " $wfAssocObj.Name " is referencing wrong TaskList" -      ForegroundColor Red;
 $wfAssocObj.SetTaskList($taskList);
 $list.UpdateWorkflowAssociation($wfAssocObj);
 Write-Host "Correct TaskList mapped => OK" -ForegroundColor Green;
    }
}

-------------------------------------------------------------------------
*Note: You can modify according to your issue, hope this will help understand.

No comments:

Post a Comment