Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client script and transform map

PaulaaO
Mega Sage

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

 

1 ACCEPTED SOLUTION

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

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

View solution in original post

14 REPLIES 14

Hi,

I may not be aware of the complete setup in your instance and not completely aware of your client requirement.

I believe I have provided guidance to my fullest.

Would you mind marking my response as correct and close the question.

Regards
Ankur

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

Hi,

if you ignore it via ignore=true then entire row will be ignored.

Regards
Ankur

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

Thanks @Ankur Bawiskar  I will try a few more combinations then 🙂 thanks again for all your help!!

@Ankur Bawiskar yaaay!! it worked, all works perfect now, the ignore=true prevented the update to the other records - will need to be more careful when I use that one.

 

I am beyond happy this worked, thank you!! 🙂

Glad to help.

Please remember to mark appropriate responses helpful as well.

 

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