Variables in Tasks

Since I can create a form and have the option for input and output, for example, setting “disabled” on input so that the variable cannot be changed, I wanted to ask if there is a possibility to both pass the variable to the next task so that it can be read, and also modify it. In other words, a combination of input and output.

Hi @FC_Catalonia,

if you enable the form field and the user changes the value, then the variable will contain the changed value for the upcoming tasks (until it will be changed again).

If you want to keep the original and the changed value, you have to copy the original value before you open the form to a new variable. An easy and understandable way is to insert a script task with a feel script to save the value to a new result variable. And name the task “Save intermediate state” or with another good name.

Hope this helps, Ingo

Can you provide me with an example using the script? I’m having trouble understanding it because I haven’t encountered such a problem in other workflow management systems.

Hi @FC_Catalonia,

here is an example process containing a script task with a feel expression to save the variable value into a different variable:

The user tasks “Enter…” and “Edit…” should use a form only showing the variable data.

You can access data and data_orig later in other tasks or inspect them in Operate or Optimize.

Hope this helps, Ingo

Am I understanding correctly that data is the original variable and data_orig is the modified variable, for example, that 14 becomes 14.0 as a double?

What is a “Feel Expression”?

Hi @FC_Catalonia,

The Script task creates a copy of the value of data and saves it in data_orig.

It is a left-hand assignment, as in other programming languages.

Both values have the same type, unless you do type conversion with an additional FEEL expression like number("1500.5"), which creates the number from a string. FEEL has only a single type for number, so there is no difference between 14 and 14.0.

FEEL stands for Friendly enough expression language and allows data manipulation inside the process model, like combining variables to new variables or extracting parts of variables. You can find all details here: What is FEEL? | Camunda Platform 8 Docs

Hope this helps, Ingo

When would data manipulation be necessary, for example, in an ordering process, you wouldn’t need something like that?

Hi @FC_Catalonia,

as @GotnOGuts states in his post here, it’s mostly used when you want to reuse task workers or forms that don’t fit to the process variables that you have in your instance right now. With data manipulation, you can adjust the input for the task or adjust the output from a worker before the process variables are created.

Your first process doesn’t need data manipulation, as you have a lot of freedom to build your forms and task workers from scratch.

Hope this helps, Ingo

So it is meant to serve as a safeguard, am I understanding correctly?

Does it mean that Service Task and Script Task are exactly the same?

Hi @FC_Catalonia,

maybe a safeguard, but more to allow greater flexibility.

Under the hood, they are. But Script tasks have the shortcut to evaluate a FEEL expression without a worker implementation.

Hope this helps, Ingo

What do you mean by “worker implementation”? In what way does data manipulation offer flexibility?

Hi @FC_Catalonia,

every task needs a piece of software to be executed in an automated process. This piece of software is the “worker implementation”. Sometimes developers write their own, sometimes it is already implemented in the Zeebe Engine.

An instance of a process is driven by process variables. The implementation (see “the piece of software above”) reads the process variables, invokes some service with these variables, and saves the result of the service invocation as new process variables. In case you need a small change on a variable value before you can invoke the next service, data manipulation is useful to call two independent services one after the other.

Hope this helps, Ingo

I am completely confused now. According to the Academy videos, it is explained that pressing “instance” in the model automates the process. I thought “instance” referred to where the variables are stored, but what is the difference between an instance and a process variable?

Hi @FC_Catalonia,

A process diagram contains a model (For example, the order-to-cash process). You have to deploy it to the Zeebe Engine to automate it. Then you can start an instance of the process (model) for Order1. You can start even more instances (Order2, Order3, …).

Each instance contains process variables (For example, details of the order like customer and the list of ordered products). The variables are only visible to the process instance. Process Instance Order1 cannot see the customer of process instance Order2.

Hope this helps, Ingo

I finally understand. Thank you.