- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2020 06:19 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2020 08:34 AM
Declare variable in an onStart script and it's available to other scripts within the transform process.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2020 08:34 AM
Declare variable in an onStart script and it's available to other scripts within the transform process.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2020 10:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 07:54 AM
Hi,
So if you declare a variable using this keyword then it is accessible in all other further scripts
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2021 02:49 AM
Thank you for providing the first clear explanation (that I could find) on declaring variables usable throughout an import transform.