Question

I have created a custom workflow activity in CRM that creates a task. The workflow is attached to an a opportunity. When I create my task I would like to set the “regardingobjectid” to the guid of the related opportunity.

        ICrmService crmService = context.CreateCrmService();
        task entity = new task();
        entity.subject = taskSubject;
        entity.regardingobjectid.Value = ??????
        crmService.Create(entity);

Is this possible? I thought it would be simple.

Was it helpful?

Solution

Assuming the first few lines of your activity look like this:

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));   
IWorkflowContext context = contextService.Context;

Then you should be able to do this:

entity.regardingobjectid = new Lookup("opportunity", context.PrimaryEntityId);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top