Can you create a 'global' variable within the Transform Map?

tobrien
Kilo Guru

Hi,

We're on Helsinki...

I just finished watching a video from ChuckT. from 2014 regarding the use of a 'global' variable within a Script Include. In my case I would like something very similar to assist in a Transform Map.

To borrow from the video -- is it possible to have, say --->

OnBefore:

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

        //my Global variable??

        if (MyVAR == 'undefined')

                  MyVAR = 'some_original_thing';

        if (source.some_source_field != '')

                  MyVAR = source.some_source_field;

        else

                  source.some_source_field = MyVar;

       

//I am trying to 'recall' a value from a 'previous' row for subsequent rows that do not have that some_source_field set

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

in the video it was stated that a variable not declared with 'var' will be 'global'   --- does this work for Transform Maps?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Anthony,



Yes, you can do this with a transform script. Declare it in an onStart script and it's available to other scripts within the transform process.


View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Trade Secret



In such cases i just use session variable. Just make sure you clear it/ kill it after use.



-Anurag


-Anurag

Chuck Tomasi
Tera Patron

Hi Anthony,



Yes, you can do this with a transform script. Declare it in an onStart script and it's available to other scripts within the transform process.


Thanks, Chuck... and Anurag ...



See you at K17 !!!!