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.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

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