Search code examples
c#dynamics-crmworkflowcrm

In CRM Setting Value of two fields


In a form I have date (today date) and a delay (Whole Number) and a NextDate (=Today + delay)

I want to get just the delay from the user and set the others automatically

Here is My code:

[Input("Delay")]
[Default("12")]
public InArgument<double> Delay { get; set; }


protected override void Execute(CodeActivityContext executionContext)
{
    IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
    IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


    Entity ent = new Entity("bartar_callcenterreport");
    ent.Id = Delay.Get(executionContext).Id; 
    int delay = (int)Delay.Get(executionContext);
    ent["bartar_date"] = DateTime.Today;
    ent["bartar_nextcall"] = DateTime.Today.AddDays(delay);
    service.Update(ent);

But it gives error that update needs id, and I don't know how to get id of the current record.


Solution

  • IWorkflowContext context = executionContext.GetExtension();

    Guid Id= context.PrimaryEntityId;