elsa-workflows / elsa-core

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

Support variables in written/coded workflows #895

Open jwillmer opened 3 years ago

jwillmer commented 3 years ago

Real world problem:

As a developer I write the following example(!) workflow for a customer (not via UI):

The customer likes to query the last 10 sold items in his store and lookup his purchase price for the items in a document. Then he likes to know how much he have earned.

I implemented it and all are happy.

...

Proposed solution

As a developer I would like to define properties in my workflow that the user can set via the UI. I would then implement the example workflow like this:

The customer likes to query the last {{ ItemCount = 10 }} sold items in his store and lookup his purchase price for the items in a {{ DocumentName = "purchase_prices.xml" }}. Then he likes to know how much he have earned.

This way my customer can make simple changes by his own without my intervention. There should be an option menu in the workflow UI there the customer sees all available properties and there he can change the values of it.

image

jwillmer commented 3 years ago

This could be done quiet simple with the env variables:

In the code it could be queried like this: var count = int.Parse(Environment.GetEnvironmentVariable("ItemCount") ?? "10", 10)

and set like this: Environment.SetEnvironmentVariable("ItemCount", 10, "Description of the env variable")

sfmskywalker commented 3 years ago

@Axeleron007 implemented the foundation upon which this feature can be implemented further.

The Elsa.WorkflowSettings project implements the necessary models and services that allows us to associate user-defined settings with workflow blueprints.

Currently, this feature is used to allow the user to disable workflow blueprints by setting the "disabled" setting (which can be regarded as a system-level setting).

What we need to do to implement this task is as follows: