Need to understand what action==="Update" means in Transform Script return values

Renee-17
Tera Guru
New to ServiceNow and importing Data.
 
I have a source data and want to only update field_b in the target table if field_a exists already in the target. 
 
However, I do not want to insert a new row if field_a does not exists in target. 
 
In the transform map when I select Run Script I've added the code to ignore the insert action during the transform.  This is what I want. 
 
BUT could someone share with me if the red highlighted values should be isUpdate and action==="update"
 
I need to understand what action==="update" means and if I should have something else here?
 
(function transformRow(source, target, map, log, isUpdate) {
//Completely disallow insert on Transformation
    if(action == "insert"){
        ignore = true;
}
})(source, target, map, log, action==="update");
2 ACCEPTED SOLUTIONS

OlaN
Giga Sage
Giga Sage

Hi,

Those lines are a predefined function executing in your transform.

They are in place to prevent unintentional overwrite of variable values, in case there exists the same variable name elsewhere in the system.

By wrapping all executing code inside a function, like this one, you can safely have the same variable names in many scripts without them interfering with each other.

 

I'm not sure what the highlighted parts in the script actually mean, but I would say it's safe to let them be as is.

 

To import data according to your requirements, I would set Coalesce on field_a and then the import should work fine with your script above (or you could add the logic as a onBefore Transform Map script (image below) if you prefer, it will have the same result).

add-transform-map-script.png

View solution in original post

Community Alums
Not applicable

Hi @Renee-17 ,

 

 

To start, let's delve into the concept of self-executing functions in JavaScript. In such functions, parameter passing occurs within the lower section of the function body.

Consider the following script:

 

 
 

 

(function(param1, param2, param3) {
   if(param3){//True
     gs.log(param1);//pen
     gs.log(param2);//pencile
   }
})("pen","pencile",true);

 

 

Moving on to the script in question, it sets the variable isUpdate to true based on the action parameter. However, whether the script executes isn't solely determined by whether it's an update operation; rather, it hinges on how the script is defined within the function.

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

View solution in original post

3 REPLIES 3

OlaN
Giga Sage
Giga Sage

Hi,

Those lines are a predefined function executing in your transform.

They are in place to prevent unintentional overwrite of variable values, in case there exists the same variable name elsewhere in the system.

By wrapping all executing code inside a function, like this one, you can safely have the same variable names in many scripts without them interfering with each other.

 

I'm not sure what the highlighted parts in the script actually mean, but I would say it's safe to let them be as is.

 

To import data according to your requirements, I would set Coalesce on field_a and then the import should work fine with your script above (or you could add the logic as a onBefore Transform Map script (image below) if you prefer, it will have the same result).

add-transform-map-script.png

Community Alums
Not applicable

Hi @Renee-17 ,

 

 

To start, let's delve into the concept of self-executing functions in JavaScript. In such functions, parameter passing occurs within the lower section of the function body.

Consider the following script:

 

 
 

 

(function(param1, param2, param3) {
   if(param3){//True
     gs.log(param1);//pen
     gs.log(param2);//pencile
   }
})("pen","pencile",true);

 

 

Moving on to the script in question, it sets the variable isUpdate to true based on the action parameter. However, whether the script executes isn't solely determined by whether it's an update operation; rather, it hinges on how the script is defined within the function.

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Renee-17
Tera Guru

Thank You!