Hello all,
I would like your help whether there is a way to get from a java class the "activiti:field name" from a service Task and not only the value. For instance if we have this service task:
<serviceTask id="servicetask1" name="Service Task" activiti:class="Test">
<extensionElements>
<activiti:field name="theName" stringValue="test value"/>
</extensionElements>
</serviceTask>
And on the other hand:
class Test {
org.activiti.engine.delegate.Expression theName;
@Override
public void execute(DelegateExecution execution) throws Exception {
String value1 = (String) theName.getValue(execution);
//now value1 contains the string: "test value"
}
Can I somehow get the activiti:field name(="theName") (maybe from the bpmn file) without the need of declaring "Expression theName in the class??
Thanks in Advance,
Alexander.
Inside the execute method you can try this:
// in version 5x you can get the repositoryService using
// execution.getEngineServices().getRepositoryService()
BpmnModel model = repositoryService.getBpmnModel(execution.getProcessDefinitionId());
FlowElement flowElement = model.getFlowElement(execution.getCurrentActivityId());
List<FieldExtension> fieldExtensions = ((TaskWithFieldExtensions) flowElement).getFieldExtensions();
// loop through the list to get field extension with name you want fieldExtension.getFieldName()
// if only one extension field then should be the first element
Hope that helps.
Hello,
Thank you for the replay and yes it was indeed helpful! Furthermore, in case that someone else need it, it also works outside the execute method and even in another class like this:
FlowElement ServiceTaskName = getServiceTask(); // custom method to get Service Tasks from the repositoryService and //Bpmn model
FlowElement flowElement = model.getFlowElement(ServiceTaskName.getId());
List<FieldExtension> fieldExtensions = ((TaskWithFieldExtensions) flowElement).getFieldExtensions();
System.out.println("Extension name: "+fieldExtensions.get(0).getFieldName());//if only contains 1 element
Thanks again,
Alexander.
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.