locked
Change workflow initiator when starting a workflow programatically. RRS feed

  • Question

  • is it possible when starting a workflow through the client object model to supply a different initiator other than the account that is logged in an running the start command?

    I am using C# and going against sharepoint 2013 online from an intranet web application. We log into sharepoint using a quasi service account we setup that has full control of the web and list.

    I assume, amybe, in the start up parameters but I'm not sure how to use that and I can't find anything to help explain how to.

    this is what i have

    //WORKFLOWS
                        var workflowServicesmanager = new SP.WorkflowServices.WorkflowServicesManager(clientContext, clientContext.Web);
    
                        // connect to the deployment service
                        var workflowDeploymentService = workflowServicesmanager.GetWorkflowDeploymentService();
    
                        // get all installed workflows
                        var publishedWorkflowDefinitions = workflowDeploymentService.EnumerateDefinitions(true);
                        clientContext.Load(publishedWorkflowDefinitions);
                        clientContext.ExecuteQuery();
    
                        // find the first workflow definition
                        var firstWorkflowDefinition = (from p in publishedWorkflowDefinitions where p.DisplayName == "Asset_Disposal_Approval_WF_SP2013" select p).First();
    
                        // connect to the subscription service
                        var workflowSubscriptionService = workflowServicesmanager.GetWorkflowSubscriptionService();
    
                        // get all workflow associations
                        var workflowAssociations = workflowSubscriptionService.EnumerateSubscriptionsByDefinition(firstWorkflowDefinition.Id);
                        clientContext.Load(workflowAssociations);
                        clientContext.ExecuteQuery();
    
                        // find the first association
                        var firstWorkflowAssociation = workflowAssociations.First();
    
                        // connect to the instance service
                        var workflowInstanceService = workflowServicesmanager.GetWorkflowInstanceService();
    
                        // start the workflow
                        var startParameters = new Dictionary<string, object>();
                        //startParameters.Add("Requested By", 42);
                        //startParameters.Add("Initiator", 42);
                        //startParameters.Add("Initiated By", 42);
                        //startParameters.Add("Originator", 42);
    
                        workflowInstanceService.StartWorkflowOnListItem(firstWorkflowAssociation, 21, startParameters);
                        clientContext.ExecuteQuery();
    The work flow starts ok but again, the initiator is of the service account we use and not of the user actually pushing the button. 

    Friday, September 5, 2014 2:06 PM

All replies

  • the initiator field is analogous to the "Created By" field... not exactly something you can override.

    Server object model can fake things, but client side? not a chance.


    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

    Friday, September 5, 2014 2:59 PM
  • I can change the created by field though on a list item as it is added.
    Monday, September 8, 2014 12:16 PM