A Foreach workflow containing several scripts that publish, fill and clear an array, stopped working after upgrading from AE 12.2.3 to 12.3.8
Code of the script in the pretreatment script:
:SET &MY_LOOP_INDEX# = FORMAT(&$LOOP_INDEX#)
:SET &MY_LOOP_COUNT# = FORMAT(&$LOOP_COUNT#)
:PRINT "Loop &MY_LOOP_INDEX# / &MY_LOOP_COUNT# : list servers is &ITEM#."
:DEFINE &LIST_SRV#, string, 20
:FILL &LIST_SRV#[] = STR_SPLIT(&ITEM#,"|")
:PUBLISH &LISTE_SRV#[], TABLE_SERVERS#, "TOP"
This script fails with "FAULT_OTHER - Start impossible. Other error" and the error being:
U00021719 Syntax error in object 'SCRIPTNAME', line '00000'. 'U01001341 The index 'X' is outside of the valid area of the array 'ARRAYNAME#'.'.
Release : 12.3.x
Component : AUTOMATION ENGINE
This was working because of an internal bug fixed via AE-23118 (Automic Script with out of bounds exception is not recognized - fixed on 12.2.7+ and 12.3.4+).
In previous versions it was possible to access an invalid index, but now there is a check that prevents it and the exception is launched whenever the script tries to access a no longer valid index.
This is now working correct.
In the pretreatment script the following was used:
:PUBLISH &LISTE_SRV#[], TABLE_SERVERS#, "TOP"
This (re) creates the array TABLE_SERVERS# during each iteration at the TOP level.
In the postreatment script, the following was being used:
:CLEAR &TABLE_SERVERS#[]
This is wrong as the array already existed, and the clear removes the values only at the script level, all upper level still stay the same.
That is why during the second execution the array TABLE_SERVERS# would still display the old values from first cycle:
2022-05-24 11:24:53 - U00020206 Variable '&ITEM#' was stored with value 'SRV4|SRV5'.
2022-05-24 11:24:53 - U00020206 Variable '&TABLE_SERVERS#[00001]' was stored with value 'SRV1'.
2022-05-24 11:24:53 - U00020206 Variable '&TABLE_SERVERS#[00002]' was stored with value 'SRV2'.
2022-05-24 11:24:53 - U00020206 Variable '&TABLE_SERVERS#[00003]' was stored with value 'SRV3'.
And only after the values from the 2nd iteration:
2022-05-24 11:24:53 - U00020237 The object variable '&TABLE_SERVERS#[00001]' in object: 'SCRI.DEMO_ERREUR.PRETRAITEMENT', line: '00009' (RunID: '0003830012') has been created with the value 'SRV4' by using the command :PUBLISH.
2022-05-24 11:24:53 - U00020237 The object variable '&TABLE_SERVERS#[00002]' in object: 'SCRI.DEMO_ERREUR.PRETRAITEMENT', line: '00009' (RunID: '0003830012') has been created with the value 'SRV5' by using the command :PUBLISH.
During the third iteration the TABLE_SERVERS# already exists but with two elements due to the :PUBLISH with two elements from the second cycle.
Now an attempt is made to initialize this array but on the position(index) 3 that does not exist and that's why the error is shown:
U00021719 Syntax error in object 'SCRI.DEMO_ERREUR.PRETRAITEMENT', line '00000'. 'U01001341 The index '3' is outside of the valid area of the array 'TABLE_SERVERS#'.'.
The recommendation would be to not use the :PUBLISH at the script level during each iteration as this does not work and define the TABLE_SERVERS# once at the beginning.
Please consult with Professional Services if any help is needed to implement the required script changes.