elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.3k stars 1.16k forks source link

How to get the Instances ID of a workflow #5017

Open DannyJyc opened 7 months ago

DannyJyc commented 7 months ago

How can I set the request pointend of the http request in the workflow designer, and then obtain the Instances ID of the corresponding workflow after the request?

glime-ai[bot] commented 7 months ago

To set the HTTP request endpoint in the Elsa Workflow designer, you typically use the "HTTP Endpoint" activity. This activity allows you to specify the path that will trigger the workflow when an HTTP request is made to it. You can define the path directly in the activity's properties.

To obtain the Workflow Instance ID after making a request, you can use the IWorkflowRuntime service if you are triggering the workflow programmatically. When you dispatch a workflow using this service, it will return the Workflow Instance ID immediately without waiting for the workflow to finish execution. This is useful when you want to trigger a workflow and track its progress later on.

Here's a general outline of the steps you would take:

  1. In the Elsa Workflow designer, add an "HTTP Endpoint" activity to your workflow.
  2. Configure the "HTTP Endpoint" activity with the desired path.
  3. Make sure to publish the workflow after setting up the HTTP Endpoint.
  4. When the endpoint is triggered by an HTTP request, the workflow will start, and you can obtain the Workflow Instance ID programmatically using the IWorkflowRuntime service with the DispatchAsync method, which enqueues the workflow for execution and returns the Workflow Instance ID.

Please note that the exact code and methods to use will depend on the version of Elsa Workflow you are using and the context in which you are working (e.g., within an ASP.NET Core application, a console app, etc.).

For more detailed information and examples, you should refer to the official Elsa Workflow documentation and the sources provided in the context.