Error Starting Workflow when a new Sharepoint Item is created

So, as I mentioned in an earlier post, I was having some problems creating a workflow which I wanted to initiate when a new item was added to a forms list. Well, I think I solved it.

I could do this fine with the workflows that come with Sharepoint, but when I tried to run my own, it never worked. Whenever I added a new item, I’d get the message ‘Error Occurred’, and looking in the logs I found:

06/20/2006 12:00:28.75 OWSTIMER.EXE (0x064C) 0x0D08 Windows SharePoint Services
Workflow 72et Exception
System.ArgumentNullException: Value cannot be null.
at Microsoft.SharePoint.Workflow.SPWorkflow.GetReservedItemId( SPList list, Guid taskId, Boolean createNew)
at Microsoft.SharePoint.Workflow.SPWinOEItemEventReceiver.CreateListItemSubscription( Guid subscriptionId,
SPWorkflow workflow, SPList list, Guid channelTypeId, Guid staticCorrelationId, Guid dynamicCorrelationId,
Guid subEventType, SPEventReceiverType rt, String assemblyName, String className, String eventName,
Int32 itemId, Boolean fReserveId)
at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateSubscription(MessageEventSubscription sub)
at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CreateSubscription(MessageEventSubscription sub)

I’m still not clear what was causing this – I couldn’t find more detail – but I did get rid of it for my troublesome workflows.

I found a thing suggesting that I’d have to have event handlers for all the events on the task that I create in this workflow – that is onTaskCreated and onTaskDeleted, as well as onTaskChanged.

I also found a comment suggesting that I’d have to have the line:

workflowId = workflowProperties.workflowId

in onWorkflowActivated.

Finally, I found a mistake in one of the settings for the correlation token on the onTaskChanged event.

I fixed all of these things, and the workflow worked on a new item being added. I removed the line of code from onWorkflowActivated. The workflow still worked. I removed the unnecessary event handlers – onTaskCreated and onTaskDeleted. The workflow still worked.

I can only conclude that the problem lay with the correlation token that I fixed. My working example can be downloaded here.

What I did then was go back and check the correlation tokens being used throughout the workflows I was having problems with. I’m still not sure how these work (though I do get what they’re for). For one of my workflows, I’d set this to the same variable name as the workflowId and taskId. This was wrong. I set them just to workflowToken and taskToken, and the workflow, well, worked. I checked out another workflow that was failing – and there, for the task, I was using a correllation token called workflowToken. I changed this to taskToken for things associated with the task. (I didn’t create a correlation token anywhere – it seemed to do that itself.) Now it seemed to work too.

I should point out, I don’t see where these correlation tokens are being used, and I really don’t get how they work. Yet.

Anyway, this seemed to fix the error I was getting above for all of my problematic workflows, although I got a new error for one – where I was trying to parse initiationData, but there isn’t any for a workflow started automatically like that.

Advertisement
Error Starting Workflow when a new Sharepoint Item is created

2 thoughts on “Error Starting Workflow when a new Sharepoint Item is created

  1. mhos says:

    I fully understand this is an anciant post, but, I’m having the same error currently as you were:
    “although I got a new error for one – where I was trying to parse initiationData, but there isn’t any for a workflow started automatically like that.”

    Do you think you provide any kind of insight?

    Google has failed me thus far.

    Kind regards

  2. Hmm. It is possible, but I forget the details. It’s a long time since I did that workflow stuff, and we gave up trying to use SharePoint workflow in the end on that project (problems with Delay steps not returning)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.