SharePoint's strange behavior rattles me!!

Now you must be thinking, how can a SharePoint hardcore developer say something like this? But guys sometimes SharePoint really throws in those cute “Surprises”. J

Recently, I was working with a strange issue. I had a normal document library list, with some really normal word document items. Now this list had an OOB approval workflow associated with it. The settings of this list were configured, so that any new item added would automatically call the workflow. (Nothing special Guys – In the UI I just checked the flag for calling the workflow automatically)

Now from the UI site, try adding an item. This would kick-start the associated workflow. Cool. Now let’s try adding an item to the list through OM code. I used an elementary console application code piece to add items to the list. Now the bizarre thing happens (Although the surprise is yet to come). The workflow doesn’t get activated. There is no error shown, in fact the workflow itself is not initiated.

I researched and couldn’t find anything concrete. So as a workaround I decided to call the workflow from code in such cases. Still, I was not able to get the workflow started. On closer analysis, do you remember the initial step – I checked the checkbox for calling the workflow automatically. So just shot an arrow in the dark, and by JOE it hit the bull’s eye. And my workflow began working! (Now that’s the surprise guys). So in order to get this workflow activated you need to disable the capability of automatic activation of workflow from the UI site. (Arrrggghhh ...J)

Anyways the code to start the workflow from code:-

SPWorkflowAssociation wrkFl = translationJobList.WorkflowAssociations[0];
translationSite.WorkflowManager.StartWorkflow(newItem, wrkFl, wrkFl.AssociationData, true);

Comments