cancel
Showing results for 
Search instead for 
Did you mean: 

Multi instance using form variables

kelyannegualber
Champ in-the-making
Champ in-the-making
Hi!
I'm trying to get a job becomes multiple instance using the "collection" object people. The task has a form that needs to be filled with person data and this data must be related to the person class variables (name, age, sex ..).
I am very grateful if anyone can help me!
4 REPLIES 4

hari
Star Contributor
Star Contributor
Hi,

From the above, I understood that you want to call a sub process for every person in the collection. For that you can simply right click on the Call Activiti and open up the multi instance properties. Say for example your collection name is Persons, set it there and for Element variable you may set is as Person.  In the main config, make sure you map Person which you have set as Element Variable to the sub process variable.

kelyannegualber
Champ in-the-making
Champ in-the-making
Right! I am using these same properties multi instance you mentioned.
In my testing, I'm adding up the values of variables in a HashMap using variables.put ("name", "Kelyanne"), for example. However, I am struggling to set this value to a person object.
Like this:
Person person = new Person ();
person.setName ("Kelyanne");
My question is:
How to set the values that the user types on the form to the variables of the Person class.
The truth is that I am still beginner and not yet know the best solutions. Smiley Sad
Thanks

hari
Star Contributor
Star Contributor
Well, You can pass your Person object in the map and iterate it as suggested in my earlier post. Now in the sub process as it is only related to a single person, you type cast the Object to your Person object in the first service task and set the process variables using it.

like say for example your sub process has variables like personName, PersonAge etc. In your service task, you can set them as below.

// Below is the Person object which you have passed to the sub process
Person currPerson = (Person) execution.getVariable("Person")
//In the below step you are setting the personName process variable value from the Person object which you have received from the parent process.
execution.setVariable("personName", currPerson.getName());
execution.setVariable("personAge", currPerson.getAge());

kelyannegualber
Champ in-the-making
Champ in-the-making
Thanks so much, Hari! Now it's clear!
Smiley Happy