locked
Activate Processes for other users RRS feed

  • Question

  • I have many workflows/processes in my CRM 2011 deployment. I'm running in to a pretty significant annoyance in moving my solutions from development to production. I have workflows that are owned by system accounts, and I cannot activate them with my standard administrative account. Is there a way to avoid this so that the upgrade manager can deploy a solution and activate all processes no matter who owns them?

    Cheers,

    Dave

    Tuesday, April 10, 2012 6:02 PM

Answers

  • Hi Dave,

    Short answer is yes.

    Please refer to http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27824 but in a nutshell you'll be impersonating a user:

    public static void AssignAndPublishWorkflow(ServerConnection.Configuration serverConfig, 
                      Guid workflowid, Guid userid)
    {
        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(
                      serverConfig.OrganizationUri,
                                                               serverConfig.HomeRealmUri,
                                                               serverConfig.Credentials,
                                                               serverConfig.DeviceCredentials))
        {
            IOrganizationService service = (IOrganizationService)serviceProxy;
     
            //unpublish the workflow
            SetStateRequest unpubReq = new SetStateRequest();
            unpubReq.EntityMoniker = new EntityReference("workflow", workflowid);
            unpubReq.State = new OptionSetValue(0); //draft state
            unpubReq.Status = new OptionSetValue(1); //draft status
            SetStateResponse unpubResp = (SetStateResponse)service.Execute(unpubReq);
                    
            //assign the workflow to the new userid
            AssignRequest assignReq = new AssignRequest();
            assignReq.Target = new EntityReference("workflow", workflowid);
            assignReq.Assignee = new EntityReference("systemuser", userid);
            AssignResponse assignResp = (AssignResponse)service.Execute(assignReq);
     
            //impersonate the new userid
            serviceProxy.CallerId = userid;
     
            //publish the workflow
            SetStateRequest pubReq = new SetStateRequest();
            pubReq.EntityMoniker = new EntityReference("workflow", workflowid);
            pubReq.State = new OptionSetValue(1); //published state
            pubReq.Status = new OptionSetValue(2); //published status
            SetStateResponse pubResp = (SetStateResponse)service.Execute(pubReq);
     
        }
    }

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Michael Mayo

    • Proposed as answer by Michael D. Mayo Wednesday, April 11, 2012 4:52 AM
    • Marked as answer by Dave Maslen Wednesday, April 11, 2012 12:50 PM
    Wednesday, April 11, 2012 4:51 AM

All replies

  • Short answer; no.  You cannot activate a Process owned by someone else, without first taking Ownership of that process.

    For an excellent overview of the what, why and how of all things Process and Ownership, take a look at Gonzalo Ruiz's following blog post:

    http://gonzaloruizcrm.blogspot.com.au/2011/05/processesworkflow-ownership-faqs.html


    --pogo (pat) @ pogo69.wordpress.com

    Tuesday, April 10, 2012 10:58 PM
  • Hi Dave,

    Short answer is yes.

    Please refer to http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27824 but in a nutshell you'll be impersonating a user:

    public static void AssignAndPublishWorkflow(ServerConnection.Configuration serverConfig, 
                      Guid workflowid, Guid userid)
    {
        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(
                      serverConfig.OrganizationUri,
                                                               serverConfig.HomeRealmUri,
                                                               serverConfig.Credentials,
                                                               serverConfig.DeviceCredentials))
        {
            IOrganizationService service = (IOrganizationService)serviceProxy;
     
            //unpublish the workflow
            SetStateRequest unpubReq = new SetStateRequest();
            unpubReq.EntityMoniker = new EntityReference("workflow", workflowid);
            unpubReq.State = new OptionSetValue(0); //draft state
            unpubReq.Status = new OptionSetValue(1); //draft status
            SetStateResponse unpubResp = (SetStateResponse)service.Execute(unpubReq);
                    
            //assign the workflow to the new userid
            AssignRequest assignReq = new AssignRequest();
            assignReq.Target = new EntityReference("workflow", workflowid);
            assignReq.Assignee = new EntityReference("systemuser", userid);
            AssignResponse assignResp = (AssignResponse)service.Execute(assignReq);
     
            //impersonate the new userid
            serviceProxy.CallerId = userid;
     
            //publish the workflow
            SetStateRequest pubReq = new SetStateRequest();
            pubReq.EntityMoniker = new EntityReference("workflow", workflowid);
            pubReq.State = new OptionSetValue(1); //published state
            pubReq.Status = new OptionSetValue(2); //published status
            SetStateResponse pubResp = (SetStateResponse)service.Execute(pubReq);
     
        }
    }

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Michael Mayo

    • Proposed as answer by Michael D. Mayo Wednesday, April 11, 2012 4:52 AM
    • Marked as answer by Dave Maslen Wednesday, April 11, 2012 12:50 PM
    Wednesday, April 11, 2012 4:51 AM
  • Thanks Michael, exactly what I was looking for!

    Dave

    Wednesday, April 11, 2012 12:51 PM