cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve all variables for all processes

marfago
Champ in-the-making
Champ in-the-making
Hi,

In my project I've recently introduced Activiti in order to manage some simple but customizable processes.
Actully, what I'm trying to do is a simple page where all processes (still active and finished) will be shown with their state and some other info.
Reading some other posts I realized that the state (and info) should be managed as process variables (and so a I did), but how can I retrieve them for all processes (active and not) without span it in too many queries? Could anyone point me to the solution?
Thx
M@rco
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
What exactly do you mean by 'state'? I'm not sure if process variables are the way to go.

However, to answer your question: the simplest would be to just query the historic tables. Even if the process is not yet finished, the history already contains it. Querying on a specific variable in that historic table is done through the HistoricxxxQuery interfaces

marfago
Champ in-the-making
Champ in-the-making
By "state" I mean a business state, something that can be shown to the user (like "open", "processing", "closed", "waiting") and can be managed automatically by the engine - just as setting a process variable.
As said, it is related to business and I imagine it might be handled/modeled with process variables but if there is a better way please point it to me.

My question is also related to the way to retrieve those variables for all process. I can see 2 ways:
-querying for process variables for each process: it would imply n+1 queries for n processes
(and also would hide ended processes which are not stored in RU_ tables)
-querying for historic detail for each historic process, again with at least n+1 queries. Furthermore, it would be a little harder to find the latest updated variable value in order to retrieve the final business state of a process, and, in any case, it would require some extra code.

Am I wrong or missing anything here? Maybe there is a third way to go and get variables and process data altogether just in one query for all process instances ?

jbarrez
Star Contributor
Star Contributor
By "state" I mean a business state, something that can be shown to the user (like "open", "processing", "closed", "waiting") and can be managed automatically by the engine - just as setting a process variable.
As said, it is related to business and I imagine it might be handled/modeled with process variables but if there is a better way please point it to me.

Ok I get it. Depending on how simple your processes are, you could use subprocesses to visually separate the different steps.

Am I wrong or missing anything here? Maybe there is a third way to go and get variables and process data altogether just in one query for all process instances ?

Why would you need the state of the finished processes? Aren't they by definition 'ended'?
If you only need the runtime processes, than you could use a variable query. If you want to query the variables + load a process instance, you'll probably need a custom SQL query to do that.

marfago
Champ in-the-making
Champ in-the-making
Am I wrong or missing anything here? Maybe there is a third way to go and get variables and process data altogether just in one query for all process instances ?

Why would you need the state of the finished processes? Aren't they by definition 'ended'?
From my point of view a process might end in different business states ("resolved", "rejected", "not applicable").In any case, I think that managing business process data with Historic service interface might be not so direct.

If you only need the runtime processes, than you could use a variable query. If you want to query the variables + load a process instance, you'll probably need a custom SQL query to do that.
Is this the only way? No way through runtimeservice or historicservice interfaces?

jbarrez
Star Contributor
Star Contributor
From my point of view a process might end in different business states ("resolved", "rejected", "not applicable").In any case, I think that managing business process data with Historic service interface might be not so direct.

If it is about the end states, you could simply give them another name. The name of the end state is saved directly in the historic process instance.

Is this the only way? No way through runtimeservice or historicservice interfaces?

Let me clarify: if it is only the runtime processes which you would need, you can certainly do it through a ProcessInstanceQuery: see eg  'ProcessInstanceQuery variableValueEquals(String name, Object value)'. But when you want to combine both historical and runtime in one query, then you would need to define a new custom SQL query in your own ibatis mapping.

marfago
Champ in-the-making
Champ in-the-making
From my point of view a process might end in different business states ("resolved", "rejected", "not applicable").In any case, I think that managing business process data with Historic service interface might be not so direct.

If it is about the end states, you could simply give them another name. The name of the end state is saved directly in the historic process instance.

Yes, I can. But why aren't they tracked/logged as activities in ACT_HI_ACTINST table? I can find "start" activities but not "end" ones. Even if they there were,  it would require some extra code to extract just the last activity for active processes: as far as I can see from the code, you can just query for all historic activities and then manually filter out the most recent.
Anyway, this does not solve completely the question.Whatabout if you have to model a business state with more than one variable (maybe a state and a sub state) ?

As said, my concern is about the processes a related variables and number of queries to retrieve them.

But when you want to combine both historical and runtime in one query, then you would need to define a new custom SQL query in your own ibatis mapping.
Can you suggest/point me to some examples?
Thx
M@rco

EDIT: After googling around, I've found a very interesting post about extending activiti's native interfaces.
http://tomeklipski.posterous.com/hacking-activiti-bpm-engine-how-to-use-custom