- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2019 09:34 AM
I have a script that I want to write in a Script Includes called from a Transform Map. I also want to use results from the script in several fields. The results of the script will change for each imported record. I assume that I need to initialize the Script Includes from an onStart transform script. To avoid running the same query for each field, can I call the Script Includes from an onBefore transform script to populate variables that the different fields can reuse? How?
Here is an example scenario:
Transform map: IMPORT
Script Includes: ANIMAL
Global variables for each record: CAT, DOG, BIRD
Field1 needs the value of CAT
Field2 needs the value of DOG
Field3 runs another script X using input variables CAT and DOG
Field4 needs the value of BIRD
How do I populate variables CAT, DOG, & BIRD once for each record so I don't have to run the query separately in each field (3 times for each record)?
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 08:50 AM
You shouldn't have any issue with using a script include. In your field level mapping script make sure you call the script include like the following.
(function transformEntry(source, target, map, log, isUpdate){
//Call the IMPORT script includes ANIMAL function to update the "phone" field of the sys_user table
target.phone = new IMPORT().ANIMAL(source, target)
})(source, target, map, log, action==="update");
Then in your function within the script include make sure that you can returning the value that you want to be set into the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 08:50 AM
You shouldn't have any issue with using a script include. In your field level mapping script make sure you call the script include like the following.
(function transformEntry(source, target, map, log, isUpdate){
//Call the IMPORT script includes ANIMAL function to update the "phone" field of the sys_user table
target.phone = new IMPORT().ANIMAL(source, target)
})(source, target, map, log, action==="update");
Then in your function within the script include make sure that you can returning the value that you want to be set into the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 10:30 AM
I pulled the script includes out of the sample based on the ldaputils and created a separate script includes. That may or may not have helped. The main issue was the "message += ...' line.
After discovering the power, the script include called from a transform map will update multiple fields in the target table directly AND/or will return a single value back to the transform map script to update the target there instead.
Transform Map script:
target.field1 = IMPORT.ANIMAL(source, target); //1 option that updates the target field with the single value returned by the script includes.
(function transformEntry(source, target, map, log, isUpdate){
target.field2 = IMPORT.ANIMAL(source, target) //updates the selected field of the target record; script call must have some variable or field to work
})(source, target, map, log, action==="update");
IMPORT Script Includes:
gs.includes("PrototypeServer"); //patterned after ldaputils script includes
var IMPORT = Class.create();
ANIMAL: function(source, target){
var CAT = ... //populates the variable to in the Script Includes
var DOG = ... //populates the variable to in the Script Includes
//**BREAKS the script: message += '/nMessage expected to write to Import log but doesn't';
//**Still does not write to the import log as I would have expected but doesn't prevent the rest of the script: gs.log = ("Another message expected to write to Import log but doesn't");
target.field4 = BIRD;
target.field5 = "ServiceNow ROCKS!";
return;
}