cancel
Showing results for 
Search instead for 
Did you mean: 

How to get from properties based on task definition id

samarjit
Champ in-the-making
Champ in-the-making
I would like to enumerate the form properties based on task definition id (AlertQueueTask or AlertQueue).


   <userTask id="AlertQueueTask" name="AlertQueue">
      <extensionElements>
        <activiti:formProperty id="AlertName" name="AlertName" type="string"></activiti:formProperty>
        <activiti:formProperty id="Carrier" name="Carrier" type="string"></activiti:formProperty>
        <activiti:formProperty id="DepDate" name="DepDate" type="date"></activiti:formProperty>
</userTask>

Currently closest I could find was retrieval form+data using from fromService using taskId- formService.getTaskFormData(taskId);

On a seperate note I would like to store some fixed properties per task, which is the right place to keep such data. For example I need to store the above  list AlertName,Carrier,DepDate per task definition. Which is the right place to store it? 
4 REPLIES 4

jbarrez
Star Contributor
Star Contributor
That is indeed the correct call to get the form properties.

> Which is the right place to store it?

You could use either variables that are injected by a tasklistener or you could add your own extensionElement and fetch them through the BpmnModel.

samarjit
Champ in-the-making
Champ in-the-making
Thanks for your quick response.

Can you tell more about how to fetch extensionElement by BpmnModel with some code?

I also managed to get the form properties as below, is this correct approach?


ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//requires activiti.cfg.xml
ProcessEngineConfiguration  processEngineConfiguration = processEngine.getProcessEngineConfiguration();

CommandExecutor commandExecutor = ((ProcessEngineConfigurationImpl) processEngineConfiguration).getCommandExecutor();
ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {
     public ProcessDefinitionEntity execute(CommandContext commandContext) {
          return Context.getProcessEngineConfiguration()
                        .getDeploymentManager()
                        .findDeployedLatestProcessDefinitionByKey("MultipleQueue");
     }
});


TaskDefinition taskDefinition = processDefinitionEntity.getTaskDefinitions().get("AlertQueueTask");

System.out.println(taskDefinition.getTaskFormHandler().createTaskForm(new TaskEntity()).getFormProperties());
List<FormProperty> formProperties = taskDefinition.getTaskFormHandler().createTaskForm(new TaskEntity()).getFormProperties();
for (FormProperty formProp : formProperties) {
System.out.println("form prop:"+ formProp.getId() +"          type:"+ formProp.getType()+"          default value:"+formProp.getValue());
}

trademak
Star Contributor
Star Contributor
Hi,

You can use the RepositoryService getBpmnModel method to get the BpmnModel of a process definition. Then use getFlowElement to lookup the correct UserTask. On the UserTask object you can get a list of FormProperty objects.

Best regards,

samarjit
Champ in-the-making
Champ in-the-making
Hi,
Thanks for the info. I am posting the code for others to get an idea about the solution.

<code lang="java">
BpmnModel processDefinition = processEngine.getRepositoryService().getBpmnModel("MultipleQueue:22:57504");
UserTask itemDefinitions = (UserTask) processDefinition.getFlowElement("AlertQueueTask");
List<org.activiti.bpmn.model.FormProperty> formProperties2 = itemDefinitions.getFormProperties();
for (org.activiti.bpmn.model.FormProperty formProp : formProperties2) {
System.out.println("form prop:"+ formProp.getId() +"  type:"+ formProp.getType()+" default value:"+formProp.getFormValues());
}
Map<String, List<ExtensionElement>> extensionElements = itemDefinitions.getExtensionElements();
  System.out.println(extensionElements); //extension element other than form

</code>
Process definition:
<code lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:myelm="http://www.x.com/myelm"  …>
  <process id="MultipleQueue" name="MultipleQueue" >
      <userTask id="AlertQueueTask" name="AlertQueue">
      <extensionElements>
     <myelm:newelement id="mynewelementid" name="mynewelementname"></myelm:newelement>
        <activiti:formProperty id="AlertName" name="AlertName" type="string"></activiti:formProperty>
        <activiti:formProperty id="Carrier" name="Carrier" type="string"></activiti:formProperty>
        <activiti:formProperty id="DepDate" name="DepDate" type="date"></activiti:formProperty>
   </extensionElements>
      </userTask>
  </process>
</definitions> 
</code>
Output:
<code>
form prop:AlertName          type:string          default value:[]
form prop:Carrier          type:string          default value:[]
form propSmiley Very HappyepDate          type:date          default value:[]
{newelement=[org.activiti.bpmn.model.ExtensionElement@d41f816]}
</code>
-Samarjit