Tuesday, 7 March 2017

Fixed: SharePoint 2013 workflow not starting on programmatically creating new list item.


For SharePoint 2013:

Just add "Log <this message> to the workflow history list" as the first statement in the workflow.


For SharePoint 2010:

Add below code just after item creation:

using(SPSitesite=newSPSite(web.Url))
{
  foreach(SPWorkflowAssociation spwfa in list.WorkflowAssociations)
  {
   if(spwfa.Name=="WorkFlow Name")
   {
    spwfa.AutoStartCreate=true;
  site.WorkflowManager.StartWorkflow(newItem,spwfa,spwfa.AssociationData);
   }
  }

}

No comments:

Post a Comment