cancel
Showing results for 
Search instead for 
Did you mean: 

Get process variable name instead of process variable id

sorinello
Champ in-the-making
Champ in-the-making
We are creating a generic solution for form rendering, and our goal is to display all process variables from previous tasks inside current tasks.

For example, in UserTask2, the assigned use can see the values filled by previous completed UserTask1's assignee. This doesn't seem possible at the moment because getVariables(String executionId) will return a Map<String, Object>, but String is actually the process variable ID instead of process variable Name.

Is there any way around this ?

Thanks.
7 REPLIES 7

slehman
Champ in-the-making
Champ in-the-making
HistoricVariableInstanceQuery may help - if you have the process instance ID, you should be able to find all variables (though it may not cover variable values that were changed during a process). 

sorinello
Champ in-the-making
Champ in-the-making
Hello, Unfortunately this does not seem to help me. I need the variable names for displaying them in the form. Variables Id's are not good, since they are a technical concept, so I need their "pretty" names to display.

I have followed your example, but I STILL get variable Id's

I have tried the following code

<code>
#set(instanceVariables = services.activiti.getProcessEngine().getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(executionId).list())
      #foreach($historicVariable in $instanceVariables)
         Name: $historicVariable.getVariableName() value: $historicVariable.getValue()
      #end
</code>

My results are:
<blockcode>
Name: nameId value: 456464
Name: longId value: 64564564
Name: enumId value: DACI_A
Name: dateId value: Tue May 28 00:00:00 EEST 2013
Name: booleanId value: true
</blockcode>

while I was expecting something like:

<blockcode>
Name: Your Name value: 456464
Name: Amount value: 64564564
Name: Option Selected value: DACI_A
Name: Registration Date value: Tue May 28 00:00:00 EEST 2013
Name: Allowed to modify value: true
</blockcode>

Any idea ? this is pretty important use case, I wonder how nobody needed this before.
Also, I think that the API is very confusing because I see methods like getVariableName() which actually return the variable Id !!!
ANY help is appreciated.

Regards,
Sorin B.

slehman
Champ in-the-making
Champ in-the-making
I just did a quick test with this snippet (I'm using Activiti 5.12.1):
<code>
   List<HistoricVariableInstance> vars = processEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId("461").list();
   for(HistoricVariableInstance i : vars) {
    log.info(i.getVariableName());
   }
</code>,

And I got the result I expected (the values in the NAME_ column in ACT_HI_VARINST).  

Does that column in the DB actually have the names you want?  Any chance you are actually trying to get the name of the form property, rather than the name of the variable?

sorinello
Champ in-the-making
Champ in-the-making
Thank you slehman for being so fast in answering me.

1)
Let me just detail a little bit. From the Eclipse Designer, when adding a form property I fill the following fields:
* Id = myId - representing the id of the property. This is getting translated as the ID which my property will have in the form.
     <code> E.g. <input type="text" id="myId" …./></code>
* Name = My Id - representing the value I use for generating the label (pretty name/description) of my property
* Type = string, long,etc etc
* Variable - I do NOT put anything here since the form property will become automatically a variable process.

When I am on the form everything is OK. But after the task is finished if I get the process variables, it seems that I get the Id from above as my variable name, instead of getting the Name from above as its name.

I think you are right, the Name and Id are STRICTLY for forms, and If I don't specify a Variable name, the Id is automatically used. Am I right ?

2) Am I allowed to use variable names which contain spaces ? I was imagining it's like in other programming language, you are not allowed to have variables which contain whitespaces.

Waiting for your response since I am a little bit confused.

Regards.

sorinello
Champ in-the-making
Champ in-the-making
Indeed, I am allowed to use whitespaces in variable names. Also, If I fill the Variable Field, I can display the already set variables in a nice manner, the ID is not longer used as variable name. Nice.

Too bad this behavior is not documented Smiley Happy

dataexpert
Champ in-the-making
Champ in-the-making
is not possible to map form property id with variable id and form property name to variable name? thans

trademak
Star Contributor
Star Contributor
Form properties are automatically mapped with the id value to the variable name. We don't have a variable id and name, only a name attribute.

Best regards,