How to transfer data across transform scripts

Shreya Nagar Na
Tera Contributor

I need to transfer data from onBefore transform script to onComplete transform script .

6 REPLIES 6

Aman Kumar S
Kilo Patron

Hi @Shreya Nagar Na 

You can by using this keyword.

Refer to below article to achive the same:

https://www.servicenow.com/community/developer-forum/setting-and-reusing-variables-during-import-tra...

 

Best Regards
Aman Kumar

Greg Hoschar
Tera Contributor

I've submitted Introduce an Official Scratchpad Object for Import Set Transform Scripts to the Idea Portal. Please upvote it if you would like to see an officially supported method!

I have found no supported means to do this. 'current.scratchpad' and 'map.scratchpad' do not exist within transform scripts in any instance I have access to.

However, you can declare a variable in the global scope of an onStart script, which subsequent transform and field map scripts can reference.

Example onStart script:

// Global scratchpad (unofficial approach for sharing across scripts)
var scratchpad = {};

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    scratchpad.test = "Does this work?";
    gs.info(map.name + ' onStart: scratchpad.test = "' + scratchpad.test + '"');

})(source, map, log, target);
 

To confirm it works, add this snippet to any field map or transform script:

    gs.info(map.name + ' {script identifier}: scratchpad.test = "' + scratchpad.test + '"');


Caveat: This technique is not officially supported. It may break if ServiceNow changes how Import Set processing works. If you’d prefer a robust, documented approach, please consider upvoting the Idea Portal submission at the link above.