Setting and Reusing Variables During Import Transform

MGanon
Tera Guru

During an import, how do I set a variable once and reference it during other transform map stages?

We have an import that 5 different scripts:
     3 Transform Scripts: onStart (1), onBefore(2), & onAfter (5)
     1 Field Maps script (3) to identify the sys_id by multiple criteria
     1 "base" script on the Table Transform Map screen (4)

Each script has a different purpose but the scripts share certain variables of the same values calculated with the same criteria. How can I calculate the variables once and reference them in the other scripts?

I believe that the scripts process in the following order: onStart (1), onBefore(2), Field Maps script (3), "base" script (4), & onAfter (5). The onStart script only initializes (gs.include…) our custom version of the LDAPUtils Script Includes. The other scripts call additional scripts from our custom version of the LDAPUtils Script Includes.

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Declare variable in an onStart script and it's available to other scripts within the transform process.

 

Regards,

Sachin

 

 

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

Declare variable in an onStart script and it's available to other scripts within the transform process.

 

Regards,

Sachin

 

 

MGanon
Tera Guru

For clarity: "this." and not "var " in front of the variable.

Declaring a "var " variable in an onStart script does not set that variable for the rest of the transformation but a "this." variable does. Example: importBudgetItemTransform transform map

For example, add this to the onStart map:
     var DeclaredVar = "Declared Variable";
     this.thisvar = "this.variable for whole map";:

The rest of the scripts (onBefore, field mapping, run script, onAfter, etc.) will read and can use the "this.thisvar" variable but abend with the "DeclaredVar" variable.

Hi,

So if you declare a variable using this keyword then it is accessible in all other further scripts

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Goran
Tera Contributor

Thank you for providing the first clear explanation (that I could find) on declaring variables usable throughout an import transform.