Friday, 13 April 2012

Reassigning and Publishing Workflow

In this article , I am unpublished workflow and assigned new userid
and again changing workflow state draft to published
public static void AssignAndPublishWorkflow(
ServerConnection.Configuration serverConfig,
Guid workflowid,Guid userid)
         {
             using(OrganizationServiceProxy serviceProxy =
new OrganizationServiceProxy(serverConfig.OrganizationUri,
serverConfig.HomeRealmUri,
                 serverConfig.Credntials,
serverConfig.DeviceCredentials))
                 {
                 IOrganization service = (IOrganization)serviceProxy;

                 //Unpulish th workflow
                 SetStateRequest unpubReq = new SetStateRequest();
                 unpubReq.EntityMoniker = new EntityReference("workflow",workflowid);
                 unpubReq.State = new OprionSetValue(0); //draft state
                 unpubReq.Status = new OprionSetValue(1); //draft status
                 SetStateResponse unpubResp = (SetStateResponse)service.Excute(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 OprionSetValue(1); //published state
                 pubReq.Status = new OprionSetValue(2); //published status
                 SetStateResponse pubResp = (SetStateResponse)service.Excute(pubReq);

             }
         }

No comments:

Post a Comment