2

I have created a custom CRM activity that I'm using in a workflow. I'm using this activity as an InArgument to a custom workflow activity. In the Execute() method I'm trying to set the OwnerId of the custom CRM activity instance to a system user and calling UpdateObject(entity) on the context object that I have generated using CrmSvcUtil.

[Input("Some name")]
[ReferenceEntity("mycustomactivity")]
[Required]
public InArgument<EntityReference> MyCustomActivity{get;set;}


void Execute(CodeActivityContext context)
{
IOrganizationService svc = context.GetExtension<IOrganizationService>();
var customActivityReference = MyCustomActivity.GetValue(MyCustomActivity);

//MyServiceContext is an OrganizationServiceContext generated using CrmSvcUtil
MyServiceContext servicecontext = new MyServiceContext(svc); 

//GetCutomActivityInstance uses the Id to get an instance of the custom activity) 
MyCustomCRMActivity activityInstance = GetCutomActivityInstance (servicecontext,customActivityReference.Id);

activityInstance.OwnerId = new EntityReference("systemuser",<SomeGUID>);
context.UpdateObject(activityInstance);
context.SaveChanges();
}

The above does not work, the activity owner is defaulting to my crm user account and is not updated to reflect the owner I'm setting in activityInstance.OwnerId

Any help would be much appreciated.

Abhijeet Patel
  • 6,562
  • 8
  • 50
  • 93

1 Answers1

6

The owner can't be changed by update. You have to use the AssignRequest (or the built-in Assign-step, see screenshot)

See this answer https://stackoverflow.com/a/7746205/315862

enter image description here

Community
  • 1
  • 1
ccellar
  • 10,326
  • 2
  • 38
  • 56
  • Thanks for your response.Is the assign step only for plugins or also for custom acivities in CRM workflows? I will try out the AssignRequest and report back here. Also, when receiving "crm activities" such as a task or any custom activity in a workflow, the type parameter to InArgument should be "EntityReference" correct? i.e. [ReferenceEntity("mycustomactivity")] [Required] public InArgument MyCustomActivity{get;set;} – Abhijeet Patel Dec 16 '11 at 16:18
  • @AbhijeetPatel I mean the step which is available in the workflow designer. – ccellar Dec 16 '11 at 16:43
  • Did you have to end up restarting the sandbox service or async procesing service? I noticed that my code changes to the activity for changing ownership were only picked up after recycling these services. – Abhijeet Patel Dec 17 '11 at 03:23
  • @AbhijeetPatel it's imho not documented for Dynamics CRM 2011, but yes. After recycling the async service it reloads the available workflow activities – ccellar Dec 17 '11 at 13:19
  • :Glad to know that I was not going crazy. The hardest part about CRM seems be that things such as these are not documented. – Abhijeet Patel Dec 17 '11 at 21:14