Attach variables to Signal Event

Hey guys,
My task is to attach variable to Signal Event using Camunda Modeler (1.0) only (i.e. without java code).
My first process sets variable using groovy script (execution.setVariable(“variableName”, “variableValue”) then broadcasts event.
Second process tries to displays value for the variable using groovy script (println “Signal received. variableName is $variableName”). But it fails with Caused by: groovy.lang.MissingPropertyException: No such property: variableName for class: Script2.
Where am I Wrong?

${VariableName} ? or execution.getVariable(“VariableName”)

The problem is that receive process don’t contain variables at all. I’ve attached sample receive process here. receive_signal.bpmn20.xml (3.1 KB)

if you know the name of the variable before hand, you can declare it as “varname”: “”. Then you give it the value you want and the compiler wont complain.

Yeah, but variable is declared inside the “send” process, but I want to have its value inside the “receive” process. Here is the problem…

The problem you have is that you are using a variable that you have not declared before. So the compiler in camunda is saying that it can’t print “variableName” because it does not know what “variableName” is. You are trying to print the value of an undeclared variable. The structure should be like this.

Receiver:
Declare variableName.
Receive signal -> Assign value to variableName.
Print variableValue.

Sender:
Declare variableName.
Assign value to variableName.
Send signal with variable Attached.

Cheers, Gonzalo

Thank you for reply, Gonzalo. But where should I declare variable inside “sender” process? Do you mean that execution.setVariable is not enough so that’s why my variable has not been attached to the signal?
Also, where should I declare variable inside “receiver” process in order that this variable being initialized after signal start event?

In the receiver process you can declare the variable as an output parameter of the receiver signal event.

Or simply declare it on instantiation with an empty value:
rest body:
{
“variables”:
{ “variableName” : “”},
{…}
}

In the sender process the declaration is made with the execution.setVariable(“varName”, “varValue”). But be aware, if that is executed in an external script or a java delegate, I think (not 100% sure) that the scope of the variable is limited to the script or delegate. If you want to use it somewhere else in the process, you should use an OutputParameter or declare the variable on instantiation.

It’s not possible to setup input vatiables for Start Signal Event in the modeller. Should I modify bpmn file manually?
And I don’t use REST for the process instantination. “Sender” process throws signal, “receiver” process catches it.

To reformulate my question: how to pass variables from one process to another if these processes don’t binded explicitly (like process-subprocess pair)? How to share variables between the processes that are binded by Signal Event only?

Hi Eugene,

currently, you can’t send an intermediate signal event / signal end event with payload. You can only use the Signal Api and throw the signal with payload via Java Code.

Best regards,
Philipp

Thank you, Philipp, I catch you.

My current customer has the same issue and he is not the first one asking for it. Could a pull request have a chance here?

4 Likes