How do I know that whether record is inserted or updated using transform map script

SD40
Tera Contributor

How do I know that whether record is inserted or updated using transform map script 

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

So if you use an onBefore script there is an "action" variable that will tell you if its going to update or insert a new record.

https://docs.servicenow.com/bundle/sandiego-platform-administration/page/script/server-scripting/reference/r_MapWithTransformationEventScripts.html

View solution in original post

8 REPLIES 8

SD40
Tera Contributor

then syntax will be if(action=='insert)..am I right??

Allen Andreas
Administrator
Administrator

Hi,

As you mentioned, you have access to "action" which will tell you if it classifies as an insert or update.

Is there anything specific you wanted to discuss regarding that or did you just want to confirm it?

You're on the right track! 🙂

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

You can use, example:

if (action == "insert") {
//do x
}

Further example here and this can even be done in onBefore: https://docs.servicenow.com/en-US/bundle/sandiego-platform-administration/page/administer/import-set...

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Michal Hancar1
Tera Contributor

For anyone wondering, in the "onAfter" Transform Script, you can find out by the following code:

 

if(source.sys_import_state == 'inserted'){
// do magic
}

 

After the record gets processed, the transform map engine goes back and updates the import set row record. At which point you can access it via the "source" object.

MichalHancar1_0-1680594800535.png