Freemarker Script: Greater than 4000 char, exceeding historic variable instance DB insert

Thank you Stephen, finally I used Extensions instead of inputParameters (also possible to declare in Camunda Modeler template, but length is not limited as String variable). And similary as you proposed I have implemented Execution Listener (or Java Delegate) method where I am able to read the Extensions and work with them - render FreeMarker code and then store it as a File for example.

How to read Extension properties:

public class MyJavaDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution delegateExecution) {
        // get extension properties
        FlowElement flowElement = delegateExecution.getBpmnModelElementInstance();
        ExtensionElements extensionElements = flowElement.getExtensionElements();
        Collection<CamundaProperty> properties = extensionElements.getElementsQuery().filterByType(CamundaProperties.class).singleResult().getCamundaProperties();

        // go through the properties
        for (CamundaProperty property : properties) {
            String propertyName = property.getCamundaName();
            String propertyValue = property.getCamundaValue();
        }
    }
}

How to render FreeMarker template manually:

public class MyJavaDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution delegateExecution) throws ScriptException {
        String someFreeMarkerTemplateInput = "Your e-mail address is: ${emailAddress}";

        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("freemarker");
        ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();

        // create bindings based on current process variables
        Bindings bindings = scriptingEngines.createBindings(scriptEngine, delegateExecution);

        String rendered = (String) scriptEngine.eval(someFreeMarkerTemplateInput , bindings);
    }
}

Greetings, Jan.

1 Like

Thanks for sharing!