When a transform map creates a new reference record, also do...?

MarkD
Tera Expert

Not super familiar with transform map scripts - hoping someone can shed some light on a question I have.

We're importing users from AD, and when a new location is found on the user record it gets created in the location reference field (via the "Choice Action: Create" option).

find_real_file.png

Now if I wanted to add more values to this location record (cmn_location), which is data that can also be found in my import, where would be the best place to do that? 

Should I write a business rule that is triggered when cmn_location records are created?   The positive would be that it would only trigger once for each new location.  The negative is that it's a business rule and the next admin to come along would have trouble understanding where the update is happening since it's not specifically part of the import/transform.

Or should I write an onBefore transform script?  This would be part of the transform, easy to understand.  But it would run for every user checking to see if the user's location was missing information.  We have a lot of users so this doesn't seem very efficient.

Ideally I'd like this script to only run when new locations are created as a result of the "Choice Action: Create" option.  Is that possible?

I noticed the OnChoiceCreate transform script type, however it seems to only apply for choices, whereas this is a reference.

 

Any guidance would be appreciated!  Thanks

1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

You can write OnForeignInsert Transform script.

 

The onForeignInsert event script is processed at the start of the creation of a related, referenced record, before the record is created.

 

 

onForeignInsert will be called if there is a related record to insert.

 

Hope that helps.

View solution in original post

3 REPLIES 3

suvro
Mega Sage
Mega Sage

You can write OnForeignInsert Transform script.

 

The onForeignInsert event script is processed at the start of the creation of a related, referenced record, before the record is created.

 

 

onForeignInsert will be called if there is a related record to insert.

 

Hope that helps.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onForeign insert transform script as mentioned.

OR

You can use onBefore transform script and remove the field map for that Location field

a) in onBefore check if the location exists; if yes then map

b) if not then create location with the fields from import set; attach the new location in the target reference field

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Afrith Shariff
Tera Guru

Hi,

in this scenario i would prefer before script.

for more information kindly refer the link below.

https://docs.servicenow.com/en-US/bundle/sandiego-platform-administration/page/administer/import-sets/task/t_AddOnBeforeScriptToTransformMap.html