elsa-core icon indicating copy to clipboard operation
elsa-core copied to clipboard

Set variable value before execution programmatically

Open erimary24 opened this issue 1 year ago • 2 comments

I'm using Elsa 3.2, in a custom INotificationHandler<WorkflowExecuting> I want to add a new variable to the workflow variables before its execution; the problem is that WorkflowExecutionContext.Variables is immutable... how can I do?

erimary24 avatar Aug 12 '24 09:08 erimary24

Hello,

what have you done ?

For example, I use : INotificationHandler<WorkflowExecuting>

And then in the implementation

public Task HandleAsync(WorkflowExecuting notification, CancellationToken cancellationToken)
{
    notification.Workflow.Variables.Add(new Elsa.Workflows.Memory.Variable("MyCustomVariable", "MyCustomValue"));
         
}

This should works.

jdevillard avatar Aug 12 '24 10:08 jdevillard

It works, thank you!

My code wasn't working because I used "notification.WorkflowExecutionContext.Variables" instead of "notification.Workflow.Variables"... What is the difference between these two?

erimary24 avatar Aug 13 '24 08:08 erimary24