Wednesday, October 7, 2009

Starting child sharepoint workflow from a custom parent workflow

In case you need to encounter a case when you want to run child work flow from you parent share point work flow the obvious option would be the invoke Work flow activity.

It is out of box and run asynchronously naturally same goes in my mind. I tried it in my parent work flow and result was very strange. Invoke work flow activity works fine but none of the child flow get started.

I tried debugging and found several errors generated by work flow runtime few of them are mentioned below

System.Workflow.Runtime Information: 0 : CorrelationToken Uninitialized for owner activity
System.Workflow.Runtime Information: 0 : CorrelationToken Uninitialized for owner activity
System.Workflow.Runtime Critical: 0 : Uncaught exception escaped to the root of the workflow.
In instance in activity
Inner exception: System.Workflow.Runtime.Hosting.PersistenceException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.SaveWorkflowInstanceState(Activity instanceState, Boolean unlock)
at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)
--- End of inner exception stack trace ---
at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)
at System.Workflow.Runtime.WorkflowExecutor.ProtectedPersist(Boolean unlock)

I did lot of searching on and find an interesting article (http://www.sharepointnutsandbolts.com/2008/02/invokeworkflow-child-workflows-not.html) that help to to divert my attention to other workarounds

Now I start believing that invokeWorkflow will not work for me and looked for alternative and find an easy way to activate flow using Code Activity.

I simply write following code and luckily it did the same job as was expected.

SPWorkflowAssociationCollection associationCol = this.workflowProperties.List.WorkflowAssociations;
foreach( SPWorkflowAssociation association in associationCol )
{
if( association.BaseId.Equals(new Guid( "" ) ) )
{
this.workflowProperties.Site.WorkflowManager.StartWorkflow( workflowProperties.Item, association, "", true );
break;
}
}

I hope this post will help other user to find solution quickly.

No comments:

Post a Comment