TN AppSvr308 How to update an array within a for loop in an Application Server script.
Description
This article from InSource shows an example script for updating an array within a "for loop" using an Indirect tag.
- Author: Joseph Hefner
- Published: 08/28/2018
- Applies to: 17.0 and above
Details
The steps below give you an example script for copying the values from one array into another.
Step 1) Create two arrays for this test. Populate the first one with values, but leave the second array blank.
Step 2) Create a way to trigger a script to copy one array into the other one. In this test, I have called this attribute "Trigger"
Step 3) Create a script to copy the values from one array into the other. This script includes using an indirect tag and a small wait at the end of each iteration of the for loop. This may not always be necessary but has been included as an example.
The script above can be copied from below:
dim n as integer;
dim timeout as integer;
dim i as indirect;
dim s as string;
timeout = 0;
s = "Me.MyArray1";
for n = 1 to 10
s = s + "[" + n + "]";
i.BindTo(s);
while(IsGood(i) == 0);
if timeout >= 1000 then
exit while;
LogMessage("IF statement timeout occurred");
endif;
timeout = timeout + 1;
endwhile;
timeout = 0;
Me.MyArray2[n] = i;
LogMessage( "n = " + n + " s = " + s + " i = " + i );
s = "Me.MyArray1";
System.Threading.Thread.Sleep(20);
next;
Step 4) Trigger the script by setting the Trigger to True. You should notice all of the values from the first array being copied into the second array.
Before:
After: