Using our List
Now we want to get to the point of this and use the list. Here we select a set of Folders from a listbox, and then edit each in turn, all in the same session. We keep a count of the element used. Each time around we set the Folder Id of the next one and process it until we have done them all.
graphic
We have two simple processes.
graphic
The first creates a Folder, and lets you select any number of child folders from the second process.
graphic
The second is merely a create and delete for the child folders we will be going to select.
graphic
We have three forms.
graphic
One for the first action on the main process.
graphic
Here we select the folders from our fabricated ‘child’ Process. This variable will contain a tab delimited list of folder Ids.
graphic
For the Child Folder we have a plain form with a subject and three variables.
graphic
We have a very similar form for the main process, in fact with a little fancy footwork we could use the same form, but we are going to keep this simple.
graphic
Here you can see the Business Objects we have applied to the form. Most importantly for our purposes, we have the Business Object for the D_ListChild process, and we are passing in the CurrentChildId variable as the Folder id.
What we are going to do is process the list of Folder Ids we have stored, and assign each one in turn to the CurrentChildId variable in order to allow us to edit the data for that Folder.
graphic
This is the only place in either Process where we do anything in code.
graphic
Here you can see that we are calling the function we created in the first section, and passing in the ‘SelectedChildren’ variables that we fill from the listbox in the first Action.
There are two things to note here:
Firstly we are able to use the square bracket “[n]” operator to get a specific item from the returned array. That is not terribly clear, but to those used to C# (or C++/C, I am going to call these Cx from now on) it is common enough shorthand. Get used to this type of shortcut in Metastorm BPM 9, as we are now in C# land, and you will have to become a ‘semi-colonist’ like the rest of us.
Secondly we have used the “++” operator to increment the CurrentChildNumber counter variable at the same time as use it. “--” will decrement a number, by the way, and either operator before the variable it will apply the increment/decrement before using the variable (actually a surprising number of Cx programmers are unaware of that one). I’ve never seen both used at the same time, but in theory it is valid!
What is nice is that these operators are implemented for Metastorm number variables.
In ‘normal’ Metastorm BPM style, in theory, we would have assigned the return to a variable, used the square brackets operator to get the value we wanted, and then incremented the counter by adding 1. The problem is immediately seen that once we assign the return value to a variable it will become a tab delimited string straight away, and the square brackets will not work. Hence our little shortcuts here. The alternative is to do it in C#, and we were trying to keep it simple.
graphic
The only other thing we do with our list is decide what the next chained Action will be.
Here you can see the test is if the CurrentChildNumber counter is less than the number of items in our list we perform the Edit Child Action, otherwise we perform the ‘Finish’ Action. Bear in mind we are dealing with is a ‘zero-based’ arrays, so if it has 5 elements, element ‘0’ is the first, and ‘4’ is the last.
The only point to note is the “.Count” after the function call. Again, this is a shortcut. The function returns a List object, and one of the properties is Count, which is the number of items in the list.
See:
Conclusion (Next)