Fail defining ConditionExpression language

If a create a conditionExpression assigning a language to it, for example:

String condition = " variable > 100";
ConditionExpression conditionExpression = bpmn.newInstance(ConditionExpression.class);
conditionExpression.setLanguage(“JavaScript”);
conditionExpression.getDomElement().addCDataSection(condition);

And add it to a sequenceFlow:

sequenceFlow.setConditionExpression(conditionExpression);    

When I try converting the model into a string;

String xml = Bpmn.convertToString(bpmn)

I receive the following error:

Attribute 'language' is not allowed to appear in element 'conditionExpression'.

I am currently using API 7.5.0:

<dependencies>
    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine</artifactId>
        <version>7.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.camunda.bpm.model</groupId>
        <artifactId>camunda-xml-model</artifactId>
        <version>7.5.0</version>
    </dependency>

</dependencies>

Hi @pisaruk,

it seems to be a bug in the BPMN Model Api. Thanks for reporting! I created an issue for it.
As a workaround, you can convert the model without validation:
IoUtil.convertXmlDocumentToString(bpmn.getDocument())

Do you want to provide a pull request to fix this bug?

Best regards,
Philipp

Hi there,

Do you know where I should start looking at for fixing this issue?

Best Regards,
Fabio

Hi Fabio,

I’m not sure. It can be that you have to set the type attribute of the conditionExpression:

xsi:type="tFormalExpression"

If you try then it fails with the error message "can’t set the type to ‘tFormalExpression’ ". I think it’s related to the xsi namespace.

Best regards,
Philipp

Hi Fabio,

I tested a bit more. The following code should work:

definitions.setAttributeValueNs("http://www.w3.org/2000/xmlns/", "xmlns:bpmn", "http://www.omg.org/spec/BPMN/20100524/MODEL");

//...
ConditionExpression conditionExpression = bpmn.newInstance(ConditionExpression.class);
conditionExpression.setTextContent("variable > 100")
conditionExpression.setType("bpmn:tFormalExpression");
conditionExpression.setLanguage("JavaScript");	
// attach to sequence flow	

But it feels a bit ugly and unstable. Do you have an idea how to fix / improve this?

Best regards,
Philipp