
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2021 06:33 AM
Hi,
I'm working towards implementing an email integration and I am at the stage where I created the transform map, which works fine, however the table that gets the data import (sys_user) also has 2 fields that calculate the value based on other fields (which in turn get their data from the import).
Just to bring it to life:
-> contract start date (field gets populated via import)
-> 2 year tenure (fields gets populated based on the contract start date field value)
The thing is that before creating the data source and transform map I created a client script "onChange" to run on the 2 year tenure field so it would calculate the value based on the contract start date. This does work if I add the value manually, however it does not when the transform map is run.
I would appreciate some help on how to amend this - do I need to change the client script from "onChange" to "onLoad" or something else and can you point me to some scripts that could help me achieve that, as I don't have any experience in this dpt.?
Thank you 🙂
Paula
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2021 04:48 AM
Hi,
small change
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
//update the fields if there are existent values
if(action != "update"){
//empty
}
var Ctype = source.u_contract_type.toString();
var gdt = new GlideDateTime('2199-12-31');
//If any other value apart from Permanent, Contractor, FTC
if (Ctype != "FTC" && Ctype != "Permanent" && Ctype != "Contractor") {
ignore = true;
}
// Set value to 31st Dec 2199 if the contract type is "Permanent"
if (Ctype == "Permanent") {
target.setValue('u_contract_end_date', gdt);
}
else if (Ctype != "Permanent") {
ignore = true;
}
}
)(source, map, log, target);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 09:23 PM
Glad to help.
-> can we create more than one script of the same type "when" (i.e. onBefore, onStart, etc?) with different order or is it best practice to collate the conditions into 1? I am asking this as I am looking now to apply to my transform map:
a) each type has it's own meaning onBefore, onStart etc
onBefore runs before update happens on the target record
onAfter runs when every single row is transformed
-> set Contract end date field as 31/12/2199 if the Contract type is 'Permanent' and
a) this can be done via transform script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var gdt = new GlideDateTime('2199-12-31');
target.setValue('contract_end_date', gdt);
})(source, map, log, target);
-> a short script to also update the fields for future data sources being ran against the same records (hope this makes sense)
a) fields will get updated based on Coalesce field which you will be setting as True
-> if match found in target for that Coalesce=True then it would update in future
-> if not found then it would create
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 09:24 PM
@Paula
Hope this helped.
If my response helped please mark it correct and close the question.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2021 04:18 AM
Thank you
In the end the tenure calculation have covered it via a Business Rule so the field would get updated both when the transform map is ran and when there is manual update.
With the below I am trying to achieve the following:
1. transform map to update records if there are existent values (i.e. as an example if the start date of an user changes, the transform map to overwrite existent value); my coalesce field is the user_id and the coalesce is true for this one
2. if the contract type is anything besides the 3 categories the import to be ignored
3. if the contract type is permanent to update the end date to 31/12/20199 (for the other categories to just pick the values from the source fields)
Thank you!!
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
//update the fields if there are existent values
if(action != "update"){
//empty
}
var Ctype = source.u_contract_type.toString();
var endate1 = target.u_contract_end_date;
var gdt = new GlideDateTime('2199-12-31');
//If any other value apart from Permanent, Contractor, FTC
if (Ctype != "FTC" && Ctype != "Permanent" && Ctype != "Contractor") {
ignore = true;
}
// Set value to 31st Dec 2199 if the contract type is "Permanent"
if (Ctype == "Permanent") {
target.setValue(endate1, gdt);
}
else if (Ctype != "Permanent") {
ignore = true;
}
}
)(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2021 04:48 AM
Hi,
small change
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
//update the fields if there are existent values
if(action != "update"){
//empty
}
var Ctype = source.u_contract_type.toString();
var gdt = new GlideDateTime('2199-12-31');
//If any other value apart from Permanent, Contractor, FTC
if (Ctype != "FTC" && Ctype != "Permanent" && Ctype != "Contractor") {
ignore = true;
}
// Set value to 31st Dec 2199 if the contract type is "Permanent"
if (Ctype == "Permanent") {
target.setValue('u_contract_end_date', gdt);
}
else if (Ctype != "Permanent") {
ignore = true;
}
}
)(source, map, log, target);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2021 06:15 AM
Thank you
// Set value to 31st Dec 2199 if the contract type is "Permanent"
if (Ctype == "Permanent") {
target.setValue('u_contract_end_date', gdt);
}
else if (Ctype != "Permanent") {
ignore = true;
}
The update one did not work, as the field values remained the same after I ran the transform map. I am not too sure about the below one - it looks like it might work, but because the update one is not picked up correctly I cannot be 100% sure.
//If any other value apart from Permanent, Contractor, FTC
if (Ctype != "FTC" && Ctype != "Permanent" && Ctype != "Contractor") {
ignore = true;
}
I am ok to skip the above, but I really need the update part of the script to work as I will have situations where values will be overwritten via the import. If you could help me out with this last thing would very much appreciate it.
Thank you and aware I've taken lot of your time already!!
Regards,
Paula