views:

331

answers:

1

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.

+2  A: 

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);
Matt
Thank you Matt. Thats just the trick.
Chris Jones