{WorkAround} Trying to import solution error: “This process cannot be activated or deactivated by someone who is not the owner” in Dynamics CRM 2011/2013

We faced the issue during import of solution to new organisation containing 100+ processes. Microsoft suggests to assign all workflows to the user who is going to import the solution. Refer: http://support.microsoft.com/kb/2626779/en-gb

We did not want to manually go and assign all this stuff to the new user. Hence, execute following server side code to achieve the same on target organisation:

 

WhoAmIRequest request = new WhoAmIRequest();

WhoAmIResponse response = (WhoAmIResponse)service.Execute(request);

QueryExpression query = new QueryExpression("workflow");

query.Criteria.Conditions.Add(new ConditionExpression("statecode",ConditionOperator.Equal,0));

EntityCollection processCollection = service.RetrieveMultiple(query);

foreach(Entity process in processCollection.Entities)

{

AssignRequest assign = new AssignRequest

{

//systemuser; i.e., User to whome you are assigning the entity to

Assignee = new EntityReference("systemuser", response.UserId),

//Current record which you are assigning to the user

Target = new EntityReference("workflow", process.Id)

};

// Execute the Request

service.Execute(assign);

}

The solution will start exporting after this without an error. Hope it helps!

Note:- You need to be System Administrator to be running this code.

Advertisements

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 )

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