Magnolia Workflow: Passing parameters from XML to Java and contrariwise

Magnolia Workflow: Passing parameters from XML to Java and contrariwise

There may come a day when you’re in need of letting the workflow author be able to decide which input values should go into your custom command and also let him decide how to act on the output value you inject back into the workflow xml. Thanks to this article you’ll be perfectly prepared in case of emergency.

<!-- set an input parameter in the workflow xml -->
<set field="myField" value="myValue"/>

<!-- call custom command in the workflow xml -->
<participant ref="command-catalogName-myCommand"/>
// in your java command class get the input param of the workflow
String myField = (String) ctx.get("myField");

// do some processing

// inject result into the workflow xml
ctx.put("myCustomField", "myCustomValue");

<!-- access the injected command result in the workflow xml -->
${field:myCustomField}

<!-- or maybe wrap it into a conditional -->
<if test="${field:myCustomField}">
    <!-- do if myCustomField is true -->
    <!-- do if myCustomField is false -->
</if>

<if test="${field:myCustomField} == someString">
    <!-- do if comparison is equal -->
    <!-- do if comparison is not equal -->
</if>

You can find further resources below: