Get the instance number

Hi everyone,

I have a task which is iterative using a list.
I need a variable which indicates the number (id) of the active instance of the task (1 for the first instance, 2 for the second instance, …)

Is there any way I can have that variable ?

Maybe using the sequential multi-instantiation and the variable set to numberOfCompletedInstances +1 ?
Is there a solution for the parallel multi-instantiation?

Thank you :slight_smile:

Hi.
If your list contains no duplicate, you can do this :

MyList.getIndexOf(CurrentInstanceElement);

Where “MyList” is the list you iterate on, and “CurrentInstanceElement” is the element of the list that is assigned to the instance.

For example, if my list is MyList = [‘A’,‘B’,‘C’,‘D’,…], the first instance of the task has the element ‘A’, the second has ‘B’, the third has ‘C’, …
MyList.getIndexOf(‘A’) => return 0
MyList.getIndexOf(‘B’) => return 1
MyList.getIndexOf(‘C’) => return 2

Hi Yannick, thanks for your answer.

But are you sure it’s getIndexOf() ?
because I get this error groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.getIndexOf() is applicable for argument types: (java.lang.Long).

and the number returned is null.

Sorry, this is just "IndexOf()’ :
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#indexOf(java.lang.Object)

No problem, thank you again but it still returns null…

I’m using this in an operation, instanceID takes value of

return fileslist.indexOf(docID)+1;

And then I’m mapping this instanceID to a subprocess variable sub_instanceID. All of these actions, I’m doing them in the same step.

Am I doing it the right way?

I think that the operation is executed before the multi-instantiation. That’s why the variable “docID” is null and “fileslist.indexOf(null)” return null.

I try the add the “return fileslist.indexOf(docID)+1;” in a form and it return the good result.

Well, I mapped the whole fileslist to sub_fileslist instead of mapping the Integer instanceID. And I used an operation in the subprocess.

Thanks, this worked like a charm :).