How to iterate through scripts

To iterate through a script to set or extract variable information, where the variable data are in the form dataItem1, dataItem2, dataItem3, ..., dataItemnn, you need to use a workaround.

Part of the problem with iteration is that the $ token, which is used to extract variable information, can only operate on a single parameter at one time, whereas the desired information would need to be nested in the iteration loop, in the form $varName$counter$$. Hardcoding the variable name is not a viable solution for this problem.

The following workaround takes advantage of the ReadDictionary function of XML.

In this example, data was obtained from a web server in the following format:

GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity.1.n:ActivityText;value=IBOO

GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity.2.n:ActivityText;value=AFR 1621 TLV C

GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity.3.n:ActivityText;value=AFR 007 JFK CDG C

GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity.4.n:ActivityText;value=AFR 006 CDG JFK C

GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity.5.n:ActivityText;value=AFR 1621 TLV CDG C

GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity.n:ActivityText;value=JHIUSDFR

 

For which the following code works:

For nCount = 1 to 6

               strN = $nCount$ & "."

               If nCount==6 then strN = ""

                       LOG $ReadDictionary("GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity." & ReadDictionary("strN") & "n:ActivityText")$

Next nCount

 

The following is an example of what could be used if you want to work with different bases:


BASE = "GetFrequentFlierInformation.Response.n:PersonName.n:LastActivity."
For nCount = 1 to 6
               strN = $nCount$ & "."
               If nCount==6 then strN = ""
                       LOG $ReadDictionary(ReadDictionary("BASE") & ReadDictionary("strN") & "n:ActivityText")$
Next nCount