Freigeben über


SharePoint 2013 Workflow - Refresh/Push Latest Workflow Changes (Definitions)

During my tenure on last engagement, realized that pushing the latest changes on workflows in not working as expected and the latest changes are not effective until the sub site (web) was recreated. In my case I tried options like dissociating workflows, recreating libraries, reactivating the workflow features etc, to ensure the latest changes are pushed, with no luck. After all I identified that, upon deactivation of workflow definition feature, though the feature gets deactivated the workflow definitions continue to reside and not getting replaced upon reactivation of the workflow feature. The same can be validated by navigating to the Root Folder -> wfsvc using SharePoint Manger 2013. This is intentionally made, not to disturb any existing workflows or running instances.

 

Hence I realized the real need of workaround for addressing this issue and identified one. The idea is remove the work definitions programmatically to ensure the corresponding files are wiped off from the web. Make sure the following code is integrated to remove the workflow definitions from the given web.

 /// <summary>
/// Removes the workflow definitions.
/// </summary>
/// <param name="web">The web.</param>
/// <param name="workflowDefinitionIds">The workflow definition ids.</param>
public static void RemoveWorkflowDefinitions(SPWeb web, List<Guid> workflowDefinitionIds)
{
 var workflowServicesManager = new WorkflowServicesManager(web);
 
 if (!workflowServicesManager.IsConnected)
 {
 var notConnectedEx = new NotConnectedException();
 Logger.LogCriticalException(notConnectedEx, ErrorCategory.CommonOperation);
 throw notConnectedEx;
 }
 
 var workflowDeploymentService = workflowServicesManager.GetWorkflowDeploymentService();
 
 foreach (var workflowDefinitionId in workflowDefinitionIds)
 {
 var workflowDefinition = workflowDeploymentService.GetDefinition(workflowDefinitionId);
 
 if (workflowDefinition != null)
 {
 workflowDeploymentService.DeleteDefinition(workflowDefinitionId);
 }
 }
}

And now we can call the method to remove the definitions with specific IDs as follows.

 RemoveWorkflowDefinitions(web, new List<Guid> { new Guid("D7CA92FA-1220-4959-A806-719CBDE3DB6D") });

Note: Before deletion of any WF definition by calling the above line, Please make sure that all the workflow instances of the given workflow definition is removed/disassociated from the list/libraries .

Upon successful call to this method, you can validate and find that the workflow defintions are removed from the web Root Folder -> wfsvc.

 

Upon this, you  are good to go and activate the workflow definition feature that restores the updated (changed) version of the workflow on given site.

Comments

  • Anonymous
    January 20, 2014
    Since 10 days I am researching this problem and the only relevant information is here. Any idea why this is designed like this? VS 2012 is deleting the old definitions why the SharePoint installation is not doing this?

  • Anonymous
    January 21, 2014
    Thanks buddy. I was also facing same problem.

  • Anonymous
    January 21, 2014
    The comment has been removed

  • Anonymous
    January 21, 2014
    Sourabh, if its on-prem solution, we can integrate the code in the activation/deactivation logic of the feature that configures the workflow. (Not the feature that deploys the WF, as it doesn't support code behind). However this solution is not possible in SPO-D.

  • Anonymous
    January 21, 2014
    Hi Nik, even on VS2012, I observed that its deleting the old definitions only on the given site collection URL and not on all the site collections where the WF is deployed. The reason could be to prevent the earlier version of workflow being used. You can try incrementing the WF version to check if its redeploying the WF definition as expected.

  • Anonymous
    February 20, 2014
    Does this solution work if there are already running instances of the workflow you are trying to update?

  • Anonymous
    January 25, 2015
    This is awesome. Thanks Thiru!

  • Anonymous
    August 17, 2015
    How about a production site where you have 10s of active workflow with correspondent tasks? And how to update workflow definition on O365 where you don't have SharePoint Manager. If anyone has any answer please share as this is real scenario we are working on. Thanks.

  • Anonymous
    September 01, 2015
    The comment has been removed

  • Anonymous
    March 09, 2016
    Thiru, Gideon, thank you for very usefull information about the topic