BPMN Model API doesn't recognize asyncBefore attribute

Hello,

I’m trying to parse through a .bpmn file using the BPMN Model API, and I’m having trouble accessing the boolean “camunda.async” attribute on startEvents.

I’ve verified that my code is correctly identifying the startEvents, as event.getAttributeValue(“id”) on a startEvent event returns the correct id attribute on every startEvent I run it on. However, when I try event.getAttributeValue(“camunda:async”), I get null every time, regardless of whether or not the startEvent actually has an asynchronous before.

I’ve tried some variations on that code, trying to get something that works, but I haven’t been able to get anything other than null. For example, I’ve also tried:

Is there a way to access this attribute that I’m missing?

Thank you for your time

Hi,

you could use event.isCamundaAsyncBefore().

If this is not working which BPMN Model API version do you have and what is the Camunda namespace URL in the BPMN XML file?

Cheers,
Sebastian

Hi,

I’m using BPMN Model API version 7.4.0, and the Camunda namespace URL is http://camunda.org/schema/1.0/bpmn.

I should have mentioned that ‘event’ in my example has type ModelElementInstance. I cast it to a StartEventImpl and tried isCamundaAsyncBefore( ) but it returns false, even though there is an asynchronous before associated with the start event. Again, I tried getting the id to verify, this time using .getId( ), and that correctly returned the id for the start event.

Should this be working, or am I misunderstanding some part of the code?

Thanks again,
Matt

Hi,

this should work. Would you mind to share your BPMN XML? Or at least till the start event? Maybe I could spot the problem.

Cheers,
Sebastian

Here you go (sorry for the poor formatting):

<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_HaRfkDiwEeaGqbX70WYXXQ" exporter="camunda modeler" exporterVersion="2.8.0.201605241227" targetNamespace="http://camunda.org/schema/1.0/bpmn">
  <bpmn2:process id="demoProcess" name="demo" isExecutable="true">
    <bpmn2:startEvent id="StartEvent_1" camunda:async="true">
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:endEvent id="EndEvent_1">
      <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="StartEvent_1" targetRef="EndEvent_1"/>
  </bpmn2:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="demoProcess">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_16" bpmnElement="StartEvent_1">
        <dc:Bounds height="36.0" width="36.0" x="192.0" y="155.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="0.0" width="0.0" x="210.0" y="196.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="_BPMNShape_EndEvent_18" bpmnElement="EndEvent_1">
        <dc:Bounds height="36.0" width="36.0" x="457.0" y="155.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="0.0" width="0.0" x="475.0" y="196.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="_BPMNShape_StartEvent_16" targetElement="_BPMNShape_EndEvent_18">
        <di:waypoint xsi:type="dc:Point" x="228.0" y="173.0"/>
        <di:waypoint xsi:type="dc:Point" x="457.0" y="173.0"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn2:definitions>

Hi,

camunda:async is an deprecated attribute. It is technically the same as asyncBefore but as the model API is directly reading from the XML startEvent.isCamundaAsyncBefore() will not return the value of the async attribute. What you are searching for is startEvent.isCamundaAsync(). I hope this works.

Cheers,
Sebastian

This works! Thank you very much.

hi
I have similar issue, I am trying to get the class value from the model, but it always returns null.

 String data=oneServiceTask.getAttributeValueNs("class","camunda");
	String data1=oneServiceTask.getAttributeValueNs("camunda","class");
	String data1=oneServiceTask.getAttributeValueNs("camunda:class");

all of these return null :(.

Here’s my full function:

public List<String> getAllStatesFromBpmn(String xmlContent){
		List<String> result=new ArrayList<>();
		InputStream stream = new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8));
		BpmnModelInstance modelInstance = org.camunda.bpm.model.bpmn.Bpmn.readModelFromStream(stream);
		
		// find all elements of the type task
		ModelElementType taskType = modelInstance.getModel().getType(ServiceTask.class);
		Collection<ModelElementInstance> taskInstances = modelInstance.getModelElementsByType(taskType);
		for(ModelElementInstance oneServiceTask:taskInstances){
		
			String data=oneServiceTask.getAttributeValueNs("class","camunda");
			String data1=oneServiceTask.getAttributeValueNs("camunda","class");
			if(data==null||data.equals(""))
			result.add(oneServiceTask.getAttributeValue("name"));
		}
		return result;
	}

The namespace argument must be the URL, not the alias.

Also, instead of bumping old topics, please create new topics which helps us keep the forum organized. You can still link to other issues from there.

Cheers,
Thorben