I have added couple of properties to the Extensions tab of a user task and deployed the process. I am trying to get/access these extension properties using REST API, but I am unable to see these properties in the response JSON. Can someone tell me how to get these properties using REST API? Is it possible or not?
You have to parse the BPMNs xml
There is no API to get the values. You have to get the xml using the API and then parse the xml.
As Stephen said, that applies to a lot of values that should imo be retrievable using the API. Unfortunately that is not the case, but you can check the BpmnScanner inside the vPAV to see how you can easily retrieve values.
In case someone finds this post via googling (as I did): our solution for this problem is to add a “start” execution listener to the start event, which sets the extension elements of the start event as process variables. In principle, you could extend the solution to set the extension elements of other tasks as process variables or add this listener to multiple tasks. We implemented the execution listener with Java, works on Camunda 7.13.
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.BaseElement;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperties;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty;
import java.util.ArrayList;
import java.util.Collection;
public class getExtensionPropsDelegate implements JavaDelegate {
public void execute(DelegateExecution execution) {
try{
// Get base element
BaseElement elem = execution
.getProcessEngineServices()
.getRepositoryService()
.getBpmnModelInstance(execution.getProcessDefinitionId())
.getModelElementById(execution.getCurrentActivityId());
// Import CamundaProperties to query for them
CamundaProperties extElem = elem.getExtensionElements().getElementsQuery().filterByType(CamundaProperties.class).singleResult();
Collection<CamundaProperty> camPropCollection = extElem.getCamundaProperties();
// Parse CamundaProperties Collection to ArrayList, otherwise Nashorn JavaScript engine can't handle collection type
ArrayList<CamundaProperty> extElementsArray = new ArrayList<>(camPropCollection);
// Loop through all extension elements
for(int i=0 ; i < extElementsArray.size() ; i++){
execution.setVariable(extElementsArray.get(i).getCamundaName(),extElementsArray.get(i).getCamundaValue());
}
} catch (Exception e){
throw new BpmnError("GeneralProcessError","[getExtensionPropsDelegate.java]:There was an error parsing the extension properties.");
}
}
}