I’m using camunda jars and working on an experimental case to build custom forms for the processes. I read the docs and learnt that form variables can be fetched from form service getStartFormVariables method. consider the below code:
String processDefinitionId = "generatedFormsQuickstart:1:2503";
Gson gson = new Gson();
String result = gson.toJson(processEngine.getFormService().getStartFormVariables(processDefinitionId));
System.out.println(result);
result = gson.toJson(processEngine.getFormService().getRenderedStartForm(processDefinitionId));
System.out.println(result);
Here in result the first sysout prints {}
whereas the second prints the whole form"\u003cform name\u003d\"generatedFo...
with all variables.
I’m confused of why variables are not being retrieved but the built forms are retrieved.
Please guide
Hi @Vinodlouis,
Could you please share your BPMN?
Cheers,
Roman
<?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://activiti.org/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="_r7y_gEa-EeO5NO3lqhkDkg" targetNamespace="http://activiti.org/bpmn">
<bpmn2:process id="generatedFormsQuickstart" name="Generated Forms Quickstart" isExecutable="true">
<bpmn2:startEvent id="StartEvent_1" name="Loan Request 
Received">
<bpmn2:extensionElements>
<camunda:formData>
<camunda:formField id="firstname" label="Firstname" type="string">
<camunda:validation>
<camunda:constraint name="maxlength" config="25"/>
<camunda:constraint name="required"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="lastname" label="Lastname" type="string">
<camunda:validation>
<camunda:constraint name="maxlength" config="25"/>
<camunda:constraint name="required"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="netIncome" label="Net Income" type="long">
<camunda:validation>
<camunda:constraint name="required"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="loanAmmount" label="Loan Ammount" type="long">
<camunda:validation>
<camunda:constraint name="required"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="loanType" label="Loan Type" type="enum">
<camunda:validation>
<camunda:constraint name="required"/>
</camunda:validation>
<camunda:value id="mortage" name="Mortage Loan (5%)"/>
<camunda:value id="cashAdvance" name="Cash Advance (10%)"/>
</camunda:formField>
</camunda:formData>
</bpmn2:extensionElements>
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="UserTask_1"/>
<bpmn2:endEvent id="EndEvent_1" name="Done">
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:userTask id="UserTask_1" name="Approve Request">
<bpmn2:extensionElements>
<camunda:formData>
<camunda:formField id="firstname" label="Firstname" type="string">
<camunda:validation>
<camunda:constraint name="readonly"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="lastname" label="Lastname" type="string">
<camunda:validation>
<camunda:constraint name="readonly"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="netIncome" label="Net Income" type="long">
<camunda:validation>
<camunda:constraint name="readonly"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="loanAmmount" label="Loan Ammount" type="long">
<camunda:validation>
<camunda:constraint name="readonly"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="loanType" label="Loan Type" type="string">
<camunda:validation>
<camunda:constraint name="readonly"/>
</camunda:validation>
</camunda:formField>
<camunda:formField id="approved" label="Approve?" type="boolean"/>
</camunda:formData>
</bpmn2:extensionElements>
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:userTask>
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="UserTask_1" targetRef="EndEvent_1"/>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_3" bpmnElement="StartEvent_1">
<dc:Bounds height="36.0" width="36.0" x="82.0" y="118.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="38.0" width="100.0" x="50.0" y="159.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_UserTask_3" bpmnElement="UserTask_1">
<dc:Bounds height="80.0" width="100.0" x="204.0" y="96.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="_BPMNShape_StartEvent_3" targetElement="_BPMNShape_UserTask_3">
<di:waypoint xsi:type="dc:Point" x="118.0" y="136.0"/>
<di:waypoint xsi:type="dc:Point" x="204.0" y="136.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="143.0" y="136.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_EndEvent_8" bpmnElement="EndEvent_1">
<dc:Bounds height="36.0" width="36.0" x="366.0" y="118.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="22.0" width="36.0" x="366.0" y="159.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" bpmnElement="SequenceFlow_3" sourceElement="_BPMNShape_UserTask_3" targetElement="_BPMNShape_EndEvent_8">
<di:waypoint xsi:type="dc:Point" x="304.0" y="136.0"/>
<di:waypoint xsi:type="dc:Point" x="366.0" y="136.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="329.0" y="136.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Hi @Vinodlouis,
When I execute processEngine.getFormService().getStartFormVariables(...)
then I get the variables defined as form fields.
I am not aware of Gson
, what does gson.toJson(...)
do? Could you please just execute processEngine.getFormService().getStartFormVariables(processDefinitionId)
and check whether the expected variables are returned?
Cheers,
Roman
Hi @roman.smirnov,
I tried processEngine.getFormService().getStartFormVariables(processDefinitionId).size() which returned 5 so after spending some time on it
VariableMapImpl m = (VariableMapImpl)processEngine.getFormService().getStartFormVariables(processDefinitionId);
Set<Entry<String, Object>> mp= m.entrySet();
for (Iterator iterator = mp.iterator(); iterator.hasNext();) {
Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
System.out.println(entry.getKey() +" "+entry.getValue());
}
Here getKey() return me the key but getValue() returns null. I need the type of the variable like it says in rest API response docs as
{
"amount": {
"type": "Integer",
"value": 5,
"valueInfo": {}
},
"firstName": {
"type": "String",
"value": "Jonny",
"valueInfo": {}
}
}
Gson I just used for serialization earlier
That getValue()
returns null
is the expected behavior, since you are retrieving variables of a start form.
Could you please share the link of the docs you are mentioning?
1 Like
@Vinodlouis Could you please try to use VariablesMap#getValueTyped()
? This would for example look like this
VariableMap m = formService.getStartFormVariables(processDefinition.getId());
Set<Entry<String, Object>> mp= m.entrySet();
for (Iterator iterator = mp.iterator(); iterator.hasNext();) {
Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
TypedValue typedValue = m.getValueTyped(entry.getKey());
System.out.println(entry.getKey() +" "+typedValue.getType());
}
Cheers,
Roman
Thanks @roman.smirnov This meets my requirement. I guess this is missing in docs could be a good point to add there. 