So what is the problem?
There is no issue updating any item from the workflow. You can use workflowProperties.Item["FieldName"] = "Value" to update any field. The side effect is updating the item triggers the workflow again as it is configured to execute when item is modified. This causes the workflow to run in indefinite loop.
So what is the solution?
Create a new class within the workflow and inherit it with SPItemEventReceiver. Create two new functions called DisableWorkflow() and EnableWorkflow().
Inside DisableWorkflow() add a line –
this.DisableEventFiring
Inside EnableWorkflow() add a line –
this.EnableEventFiring
That’s it, just create a object of this class, call DisableWorkflow() just before workflowProperties.Item.Update() .Then call EnableWorkflow() after updating the item.
3 comments:
nice work dude
This doesn't work for me in VS 2010/SharePoint 2010. I get a error: An unhandled exception of type 'System.StackOverflowException' occurred.
I have still not tested this with VS 2010 and SharePoint 2010. Will update the post with my findings.
Post a Comment