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

cancel
Showing results for 
Search instead for 
Did you mean: 
ksgphellow
Active Member

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

Jump to solution

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 Solution

Accepted Solutions
daisuke-yoshimo
Senior Member

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

Jump to solution

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

18 Replies
ryandawson
Senior Member II

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

Jump to solution

Sounds like a use-case for start-forms with the forms set to have some required properties - I'd suggest to have a look at Activiti User Guide and see if it's a fit

ksgphellow
Active Member

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

Jump to solution

I'd agree with you, but I have, and need to have my own Implementation of forms and not in java, so I cant really use those.

Thanks for the Idea though.

Are there any other possibilities ? 

The main thing I need, is to just define required process variables and prompt them when looking up what process definitions I have in my repository.

Thanks in advance

ryandawson
Senior Member II

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

Jump to solution

Basically you want to store a list of the required process variables against each process definition. If that information will be in your forms then maybe you can find a way to get access to it from java or have the forms and the java get it from a common source. If it won't be in the forms or you can't get it then I guess basically you just need to capture it in a way the java can get it. If you've only a small amount of data then maybe you could put it in a properties file and check against it before you make the call to start a process. If it's more data then maybe a database table. I can't think of an Activiti-native way of doing this - probably because the Activiti way would be Activiti forms (but it's possible there is one and I'm missing it).

ksgphellow
Active Member

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

Jump to solution

Okay thanks, 

I'll think of something. 

Shame that Activiti Process Definitions cant be prompted for something like that. Would be a really nice feature.

Thanks again for your help.

daisuke-yoshimo
Senior Member

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

Jump to solution
ksgphellow
Active Member

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

Jump to solution

Those look promising, question is though, can these be prompted? Via the Repositry Service for example? I.e can I look these up somehow? Didnt find anything in the userguide regarding that.

Thanks

ryandawson
Senior Member II

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

Jump to solution

The main reason I don't think it's there is because Activiti/VariableInstance.xml at develop · Activiti/Activiti · GitHub  doesn't feature any 'required' column/attribute. You should be able to find out which are the variables for the process definition in advance of starting it (Activiti/ProcessDefinitionEntityImpl.java at develop · Activiti/Activiti · GitHub ) by querying through repositoryService.createProcessDefinitionQuery. Without the 'required' attribute you won't have everything you want.

A hack might be to use some naming convention to capture which variables are required and which not.

We'd be open to discussing contributions (for which gitter.im/Activiti/Activiti7 is the best place). I can see the value in having that as an information-only field. I doubt we'd want the engine to enforce which variables are required or not as I think we'd want to leave that to the process implementation but we could talk more about that if you like. 

ksgphellow
Active Member

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

Jump to solution

Okay, thanks for the Input, both of you. 

I'll try around with what Information you've given me and see if that gets me where I want to be =)

Thanks again for your help.

daisuke-yoshimo
Senior Member

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

Jump to solution

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());

}