Element Templates with Expressions/Variables -- Need Help

Hi there,

I’m trying to use element templates to create a custom Service Task that can use camunda variables. I setup a BPMN diagram to first run a Script Task that runs some JavaScript code to set a variable named “workDir” like this

execution.setVariable(“workDir”, ‘/usr’);

Then in my custom elements template Service Task I created a property like this:

elements.json file:

{
“label”: “Working Directory”,
“type”: “String”,
“binding”: {
“type”: “camunda:property”,
“name”: “workingDir”
}
}

So in the Camunda Modeler I have a string Label box named “Working Directory” that I want to put the text: “${workDir}” to dynamically use the variable value. This is not working for me and I need some help to know how to do this in the new Camunda Modeler.

Our team is currently using the old Eclipse camunda Modeler where our BPMN XML code looks like this:

<bpmn2:serviceTask id=“ServiceTask_1” camunda:class=“jpl.cws.task.CmdLineExecTask” name=“CmdLine”>
bpmn2:extensionElements
<camunda:field expression=“false” name=“throwOnFailures”/>
<camunda:field expression=“false” name=“throwOnTruncatedVariable”/>
<camunda:field expression=“ABORT_PROCESS” name=“onPreConditionFail”/>
<camunda:field name=“cmdLine”>
camunda:expressionls</camunda:expression>
</camunda:field>
<camunda:field expression="${workDir}" name=“workingDir”/>
<camunda:field expression=“1” name=“successExitValues”/>
</bpmn2:extensionElements>
bpmn2:incomingSequenceFlow_4</bpmn2:incoming>
bpmn2:outgoingSequenceFlow_2</bpmn2:outgoing>
</bpmn2:serviceTask>

It uses camunda::field and expression, but these are not supported in the element templates currently, right? So how can I accomplish this in the new Modeler?

Thanks!

Jim

It uses camunda::field and expression, but these are not supported in the element templates currently, right?

You are correct (cf. original forum thread, feature request).

So how can I accomplish this in the new Modeler?

You cannot accomplish this with the current version of the Camunda Modeler. Thumbs up camunda/camunda-modeler#483 and this may be addressed eventually.

I figured out how to evaluate the expression from the input string with this:

ExpressionManager expressionManager = Context
	.getProcessEngineConfiguration()
	.getExpressionManager();
  
Expression expression = expressionManager.createExpression(value);
			
Object evalValue = expression.getValue(execution);
		      
String value = String.valueOf(evalValue);