cancel
Showing results for 
Search instead for 
Did you mean: 

Define Required Process Variables and Get Information on those before instantiating a ProcessDefinition

ksgphellow
Champ on-the-rise
Champ on-the-rise

Hello there,

Is there a possibility in Activiti to define certain Process Variables as Required in a Process Definition and request a list of those required variables from a Process Definition?

The Reason I'm asking is, I want to make some sort of Process Repository for Process selection.

Since my Processes more often than not need different variables or different numbers of variables, I want to show form that dynamically adjusts for how many / which variables are needed to my user.

Is there a functionality like that in Activiti or can someone recommend a solution?

thanks in advance

1 ACCEPTED ANSWER

daisuke-yoshimo
Star Collaborator
Star Collaborator

If your goal is only to define a list of variables used in the process in the process, I think that Data objects is optimal.
https://www.activiti.org/userguide/#dataobjects

And, you can get that list by the following code.

List<ValuedDataObject> dataObjects = repositoryService.getBpmnModel("processDefinitionId").getProcessById("processDefinitionKey").getDataObjects();

for(ValuedDataObject dataObject: dataObjects){

            System.out.println(dataObject.getId());

            System.out.println(dataObject.getName());

            System.out.println(dataObject.getType());

}   ad

View answer in original post

18 REPLIES 18

Actually I looked further and found there are no calls to the getter or setter of variables on ProcessDefinitionEntityImpl in the engine. I thought that if the variables were defined in the process definition xml then they would at least be linked to the process definition entity but now I'm thinking not. The most relevant-looking tests actually just go through the runtimeService to get variables from the running instance after starting (Activiti/VariableScopeTest.java at develop · Activiti/Activiti · GitHub  with XML at Activiti/activiti-engine/src/test/resources/org/activiti/engine/test/db at develop · Activiti/Activi... ). My impression is that this is a gap.

I've also done a bit of code research and would like to make sure I havent missed anything.

Am I correct in that there is currently no way to get / lookup Process Variables of a ProcessDefinition? (Weither required or not is not important at this time).

Is so, I guess I'll have to find a way to make a database for holding these in parallel to the deployed processDefinitions.

Thanks for your input.

daisuke-yoshimo
Star Collaborator
Star Collaborator

If your goal is only to define a list of variables used in the process in the process, I think that Data objects is optimal.
https://www.activiti.org/userguide/#dataobjects

And, you can get that list by the following code.

List<ValuedDataObject> dataObjects = repositoryService.getBpmnModel("processDefinitionId").getProcessById("processDefinitionKey").getDataObjects();

for(ValuedDataObject dataObject: dataObjects){

            System.out.println(dataObject.getId());

            System.out.println(dataObject.getName());

            System.out.println(dataObject.getType());

}   ad

Ah thanks, tried around a bit with those, hadnt had the idea to get them via the bpmn model.

Yeah getting that far is atleast a good first step for my usecase, I'll be able to build up on top of that.

Thanks alot for your help.

Might be a stupid Question, but: Am I correct in that the DataObjects can only be defined programmatically or in the xml file ? and not in the Activiti Editor? 

Thanks

daisuke-yoshimo
Star Collaborator
Star Collaborator

All you can use.

  • programmatically
  • xml file
  • Activiti Editor/Activiti Designer

Hm okay, didnt find it in the editor, strange. Okay I'll have a look again.

Thank you.

daisuke-yoshimo
Star Collaborator
Star Collaborator

I'm sorry that Data Object setting diappear from Activiti Editor...

Ok, thanks for the info, no worries.

I'll just define the data objects in xml. 

Thanks again.