2

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.

Chris Jones
  • 2,630
  • 2
  • 21
  • 34

1 Answers1

2

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
  • 4,656
  • 1
  • 22
  • 32