Hi all,
I am trying to iterate a number of dynamic approval tasks using Multiple Node Instances. I learned that this is possible but I have a question about how to get the index of the current array element. For example. My CDT with a list of approvers is approverData and I can iterate the list of approvers using approverData[index].approverUser.
So suppose I set up a sub process with MNI and I want to call up these dynamic tasks, within the sub process, how can I reference the current item so I can pass rule input variables back and forth to/from form and pv, sub process and main process etc?
Thanks!
Discussion posts and replies are publicly visible
Sorry for not mentioning this to you before - in an MNI node, i.e. in the input setup, the current instance can be referenced with "tp!instanceIndex". For some reason this isn't seen when setting up a subprocess node as MNI, but you can see it i.e. if you set up a script task or user input task as MNI.
Thanks Mike!
So it's a little known thing but for sub-processes you do not need to reference instances using tp!instanceIndex - Appian just does it for you (don't take my word for it, try it out - you just have to make reference to the array you're wanting to pass items to the sub-process from)
I've found this too, though the execution has always seemed a little inconsistent and sometimes confusing.
No, it is not working as expected. It is always passing the 1st item in the array to all the instances. I may have to use a loop instead.
So I've just tried this - I created a process model that takes as its input a single text field.
I created another process model that populates an array with 100 items of text using this:
a!forEach( items: fn!enumerate(100)+1, expression: fn!concat( "Item ", fv!item ) )
and when I look at the process variables I can see this:
I am then calling my other process model as a sub-process, setting it up as MNI like this:
and setting up the call to the sub-process like this:
When I run the parent process, I can see it has started 100 instances of the sub-process. And if I open up any of the sub-process instances they all have a different value for the input text that I am passing.
So it works exactly as I described.
I confirmed this as well on 21.1 utilizing an integer array. Learned something new today! I've always just defaulted to tp!instanceindex out of habit, which always got my what I needed.
karthip, likely will just want to verify your configuration.
Can you add a second text parameter to your subprocess, and pass in a value of "=pv!myArray & "(secondary)""? I'm just curious to verify whether other ways of referencing the looped-over PV will behave intuitively or will try referring to the raw data (and thus probably pulling the first member of the array to pass)...
In that case, the entire array values are appended into each sub process. For instance with pv!var1={1,2,3,4,5} and pv!var2={"a","b","c","d","e"}, a MNI sup process running over each item in pv!var1, input to a text variable as =pv!var1 & pv!var2, each subs receives "1;2;3;4;5a;b;c;d;e".
To get the desired behavior, tp!instanceindex is the solution here:
=pv!var1[tp!instanceindex] & pv!var2[tp!instanceindex]
Resulting in:
1a
2b
3c
4d
5e
I think maybe you added a new PV in your parent process? I wanted a new parameter in the subprocess to test different ways of passing in the values in the parent's subprocess node (and to specify, testing how it works without utilizing tp!instanceIndex).