Variable handling

Hi -

Be gentle - question is probably very newbie…

I have a use-case where I’d like to create a variable to input to a Service Task. I’ve read through the Feel documentation particularly around expressions but the editor doesn’t allow spaces?

I was thinking something like (lazy-load):

=if (new-variable = null) then new-variable = 1 else new-variable = new-variable + 1

is something like this possible?

Thanks.

Zeebie 0.23.1

Essi

Hi Essi,

welcome to the Zeebe community :tada:

I’ve read through the Feel documentation particularly around expressions but the editor doesn’t allow spaces?

Good point. The zeebe-modeler plan to improve the UX for expressions. However, feel free to create an issue here: Issues · zeebe-io/zeebe-modeler · GitHub.

Yes. That should be possible in general. You could have an input mapping with a source expression

=if (new_variable = null) then 1 else new_variable + 1

and target new_variable.

Note that the variable name should not include an operator like -. Instead, it is recommended to use snake_case or camelCase.

Also, you need to ensure that the variable is present (i.e. initialized with null) before. Otherwise, we could lead to an unexpected behavior (A missing variable/nested property can not be handled · Issue #4212 · camunda/zeebe · GitHub).

Does this help you?
Do you want to discuss more about the context where the variable is used?

Best regards,
Philipp

1 Like

Thank you - great reply. I also have an issue when doing arithmetic on durations. It always seems to return null?

e.g. =duration(process.GetCustomerAccounts.wait)+duration(process.GetCustomerAccounts.wait)

process.GetCustomerAccounts.wait has a value of “P0DT0H0M1S”

The expression looks good :+1:

I assume that you create a variable with the name “process.GetCustomerAccounts.wait”, correct?
Again, a variable name should not include operators and . is also an operator :sweat_smile:

Either rename the name or use a JSON object/document variable (e.g. {"GetCustomerAccounts":{"wait":"P0DT0H0M1S"}}).

Does this help you?

1 Like

Hi Philipp - the variable is a context so its just navigation so I don’t think the variable name is the problem (I’m using variable names like this elsewhere without problems) - the Json looks like below:

{
“customerid”: “12345678”,
“GetCustomerAccounts” :
{
“executions” : 0,
“wait” : “P0DT0H0M1S”,
“maxRetries” : 3
}
}

If I just use the variable it all works and gets a delay of 1 second. If I use the expression below it returns NULL:
=duration(process.GetCustomerAccounts.wait)+duration(process.GetCustomerAccounts.wait)

Note: the variable name at the top I wasn’t using in the workflow - just a quick (bad) example.

It works for me. Let’s find out what is different :wink:

Is this the value of the variable “process”?

Please share your BPMN and the commands/steps to reproduce the behavior.

The following command works for my example:

./bin/zbctl create instance Process_0e4u1od --variables="{\"customerid\": \"12345678\",\"GetCustomerAccounts\" :{\"executions\" : 0,\"wait\" : \"P0DT0H0M1S\",\"maxRetries\" : 3} }" --insecure
{
  "workflowKey": 2251799813685298,
  "bpmnProcessId": "Process_0e4u1od",
  "version": 2,
  "workflowInstanceKey": 2251799813685300
}
1 Like

Hi philipp - getting error “Sorry, new users can only put 2 links in a post” - I’m assuming this relates to the http: links in the BPMN XML…

Thank you for sharing. That helped!

The difference is that you’re using the expression in the source expression of a variable output mapping. Currently, a temporal value can’t be stored directly as a variable. But it can be transferred into a string using the string() function.

So, the expression should be

=string(duration(process.GetCustomerAccounts.wait)+duration(process.GetCustomerAccounts.wait))

Or,

=string(duration(process.GetCustomerAccounts.wait)*2)

If this expression is used for a timer event then it can be used directly without the transformation.

Does this solve the issue?

2 Likes

Hi Philipp - yep - that was it. Awesome - thank you…

1 Like