Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read event inputs in next activity? #5306

Open
RenX313 opened this issue Apr 30, 2024 · 3 comments
Open

Read event inputs in next activity? #5306

RenX313 opened this issue Apr 30, 2024 · 3 comments
Labels
documentation Documentation is needed

Comments

@RenX313
Copy link

RenX313 commented Apr 30, 2024

Is there any smooth way to the read the "input" field of an Event triggered using the API?

At the moment I use getInput("__EventPayloadWorkflowInput"). This returns the object of the "input" field, but the Activity faults.
"Cannot read properties of null". Which is strange, because the WriteLine activity outputs the correct value, but the Activity still faults.

@RenX313 RenX313 added the documentation Documentation is needed label Apr 30, 2024
Copy link

glime-ai bot commented Apr 30, 2024

To read the "input" field of an event triggered using the API, you should ensure that the input is being passed correctly and that the JavaScript expression used to access the input is valid. The expression getInput("__EventPayloadWorkflowInput") should indeed retrieve the event payload if it's been set correctly.

However, the error "Cannot read properties of null" suggests that at some point, the input being accessed is null. This could happen if the event is triggered without the expected input or if there's a mismatch in the input key being used.

Here are a few steps you can take to troubleshoot this issue:

  1. Verify that the event is being triggered with the correct input payload. Ensure that the JSON being sent with the event contains the "input" field with the expected data.

  2. Check the workflow definition to ensure that the input is expected under the key __EventPayloadWorkflowInput. If the key is different, you should use the correct key in your getInput() function.

  3. If you are using a JavaScript expression in an activity to access the input, make sure that the activity is configured to handle the input correctly. For example, if you're using a WriteLine activity, the Text property should be set to a JavaScript expression that correctly accesses the input.

  4. Ensure that the version of Elsa you are using does not have any known issues related to event inputs. You can check the Elsa GitHub issues page for any related bug reports or updates.

  5. If the issue persists, consider reaching out to the Elsa community or support with details of your workflow definition and the steps you've taken. They might be able to provide more specific guidance based on the version of Elsa you are using and the exact workflow configuration.

If you provide the version of Elsa you are using and more details about the workflow definition, I might be able to give you a more precise answer.

This comment was generated by Glime.

@Muhammad-1990
Copy link

Hello,

Have you made any progress with this?
This is how I'm getting it done.

public class OnMyEventWorkflow : WorkflowBase
{
    protected override void Build(IWorkflowBuilder builder)
    {
      var myVariable= builder.WithVariable<string>();
      myVariable.Name = "myVariable";
      
      builder.Version = 1;
      builder.Id = "OnMyEventWorkflow";
      builder.Root = new Sequence
      {
          Activities =
          {
              new Event("myeventname")
              {
                  CanStartWorkflow = true
              },
              new SetVariable { Variable = myVariable, Value = new(context => context.GetInput<Dictionary<string,object>>("__EventPayloadWorkflowInput")!["myVariable"]) }
          }
    }
}

...and then triggered like this

var input = new Dictionary<string, object>
{
    ["myVariable"] = "myValue"
};

_trigger.PublishAsync("myeventname", payload: input, cancellationToken: cancellationToken);

@MaxBrooks114
Copy link

@Muhammad-1990 That works for you? I have tried so many different things and the set variable activity just doesn't work, including your method above. Difference for me is that I have a flowchart workflow instead of a sequence and the payload is not dictionary but a complex type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation is needed
Projects
None yet
Development

No branches or pull requests

3 participants