Description
Create global process variable without attaching it to a bpmn node using java code:
the process variable to be attached to process id and it should be used globally.
I do not want to attach process variable to a node.
Requirement:
Create global variable during process creation and these variables shall be available while process execute. we need to create process variable using java code and attach these variables to process id.
We tried below solution so far that is not working and value of process variable comes null, when we try to access is.
Not working solution1:
ExtensionElements extensionElements = modelInstance.newInstance(ExtensionElements.class);
{{ ZeebeOutput outputParameter = modelInstance.newInstance(ZeebeOutput.class);}}
{{ outputParameter.setSource(“globalVarValue”);}}
{{ outputParameter.setTarget(“globalVar”);}}
{{ extensionElements.addChildElement(outputParameter);}}
{{ serviceTask.setExtensionElements(extensionElements);}}
Issue: value of global variable is null when we want to access in in bpmn during run time.
Not working solution2:
// Create and configure the extension elements
{{ ExtensionElements extensionElements = modelInstance.newInstance(ExtensionElements.class);}}
{{ ZeebeProperty zeebeProperty = modelInstance.newInstance(ZeebeProperty.class);}}
{{ zeebeProperty.setAttributeValue(“globalVar”,“globalVarValue”);}}
{{ zeebeProperty.setName(“globalVar”);}}
{{ zeebeProperty.setValue(“globalVarValue”);}}
{{ // Add the property to the extension elements}}
{{ extensionElements.addChildElement(zeebeProperty);}}
{{ // Add the extension elements to the process}}
{{ process.setExtensionElements(extensionElements);}}
Issue: value of global variable is null when we want to access in in bpmn during run time.
Why we do not want to attach global process variable in a bpmn node?
Answer: This as per my requirement. Later I can tell more if needed.
Do we have a hidden bpmn element where we can attach process variable. if its not possible to have global process variable without attaching it to bpmn element.