How to set workflow initiator programmatically?

Problem : 

We have a client requirement like this:

There are some running nintex workflows on a list. We have made some changes to the existing workflow through code.
The updated workflow is to be started automatically by terminating the existing workflows and updating required fields.
We have successfully written a tool that accomplishes the tasks properly.

There is one issue though, we are unable to set the “workflow initiator” to the original. Since the code runs under system account, the initiator is “system account”, whereas we need it to be set with the name of the user who originally started the workflow.

There is a “read only” property of “SPWorkflowAssociation” class named author that provides the initiator id.
But we are unable to find a way to set the initiator on starting the new workflow.

Solution :

The only supported way you may be able to do this is to start the workflow in the context of the correct user.

To do this, use the SPSite constructor that take an SPUserToken object. You would need to determine the initiator of the old workflow and use this as the SPUserToken to run the code as this user when you start the new workflow.

Advertisements

About Joseph Velliah
As a SharePoint Developer my professional interests tend to be technical and SharePoint focused. I run a blog at "SP RIDER" where you can expect to read HOW TOs and scenarios that I run into during my day to day job. I hope my posts will give back a little to the community that is helped me.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: