The Case With The Multiple Parameter Script

Recently wile working on a project I came across a challenging script to write, the default behaviour of OpenScript is to record the parameters sent to the server and then play them back once correlated, meaning that if we have extra navigations we need to create them manually, so lets take at an example from a PeopleSoft implementation where depending on the client account that we used during an iteration we would have 1 or more parameters, the interface looked like the picture below with 2 parameters:

blg4.1.JPG
And like the following with 3 parameters:

blg4.2.JPG
Furthermore we had another challenge, each time we updated the drop down menu we generated a new navigation, that gave us 2 challenges a script with X navigations and X parameters for each navigation, right not what we recorded ......

So we have to build the navigations and parameters dynamically, that is to my opinion where OpenScript it's at its best making use of the Java API that it provides to add logic to your scripts, so first of all we need to find out how many parameters we have for each iteration, to do so we will use a regular expression to find the parameters:

code4.1.JPG




Note the null parameter in which we state that we would like all the matching values that we find in the HTML page to be stored as list of variables in the script, meaning that it will give us a list of all the parameters that it finds matching that regular expression.

I like to add the the parameters where easily identified as they used the following HTML;

code4.2.JPG





OK once we have the list we know how many parameters we need to update, we can get that number with the following code:

code4.3.JPG



Will give us the number of navigations that we need to reproduce to update each drop down menu

Ok so now we have a list lsSens[] containing all parameters, next we will need a list to keep track of the updated parameters, we ill call it isDone:

code4.5.JPG




Ok now we have 2 lists one with all the parameters and another one (empty at the moment) containing the parameters that have been updated, also we know how many navigations we need to reproduce to update each parameter.

Next we will need a method to update that list, we will place that just after the finish method in the script and call it findInParams

code4.6.JPG












We are now ready to start building the navigations, first of all we will need to loop the step to generate lsSens.length number of navigations, we will use a for loop for that

code4.7.JPG






Then we need to create an array to store all the parameters, the array size will be the number of static parameters + the new parameters found * 2 as there are 2 parameters to update in each case.


Even that using an ArrayList would have been easier for performance reasons I have chosen an Array, not that ArrayLists are slower but Arrays are still faster.


code4.8.JPG




Then we will start assigning the static parameters to the array.

code4.9.JPG





PeopleSoft needs to now which parameter is being updated so we will need to update this parameter with the value from the loop.

code4.10.JPG



Then we need to finish adding the static navigations

code4.11.JPG








and finally we will update the array with our new parameters, we will keep a count to update the array index and use a for loop to store the new parameters in the array:

code4.12.JPG




Then we need to update the parameters that have been processed:

code4.13.JPG




Then update the parameter that we are currently working on and add it to the isDone list

code4.14.JPG






and finally set the rest of parameters to its original value.

code4.15.JPG





We now have an array with all the parameters that we need to send to the server, first we need to close the for loop that updates the array as we do not need it any more:

}

Then we finally need to post that navigation substituting the list of parameters with the array that we just created.

code4.16.JPG



Remember to close the first loop

}

And we now have a navigation that will be executed x times with x number of parameters each time !!!!

Probably the most important lessons learnt from the script are the fact that we can get a list of matching regular expressions:

code4.3.JPG



And also that we can substitute the parameters for a List of some type e.g we can change that:

code4.17.JPG







For that:

code4.18.JPG


Making it possible to build a dynamically generated list of parameters.

Comments:

Great piece of code

Posted by Nebulous Coke on January 11, 2010 at 08:08 AM GMT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

bocadmin_ww

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today