- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:06 AM
Hello, everyone.
I have a phone number field in my Transform map that needs one of two things to happen.
- If the source Phone number is a specific value (i.e. '555-55-5555') then we don't update the target phone number.
- If the source phone number is anything else, run the script for that mapped field that will modify that phone number before updating the target phone number.
I've seen this post, Transform map script ignore particular field updat... - ServiceNow Community, which isn't exactly what my situation is. And I looked up the precedence order for how scripts run during a transform. But I can't figure out quite how to make this work for my situation.
Could someone point me in the right direction?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:26 AM
Hello @Brizky ,
You can remove the field map for phone number and write on before transform script.
You can try the below script:-
if(source.phone_number != "555-555-5555") {
target.phone_number = source.phone_number;
}
Please Mark my answers Helpful & Accepted if I have answered your questions.
Thanks,
Alka

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:28 AM
Hi,
So it sounds like you should always run the transform script, but depending on the source value different things should happen.
Something like this (pseudo-code)
if (source.getValue('somefield') == somecondition){
// when the field is 555-5555 for example
target.targetfield = '555-5555'; set the same value again for example
}
else {
// your logic here that changes/sets the target field
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:46 AM
The condition being met is where I have the confusion. Because I don't want to touch the target field at all. I want to leave that value alone and skip it. But process all of my other fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:47 AM
Thank you both for the replies!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:48 AM - edited 10-24-2023 06:49 AM
Hi @Brizky
On Field map entry, You can enable "Use source script" option & write a code as per your need.
answer = (function transformEntry(source) {
/* 1. Get the source value */
var sourceValue = source.your_field_name;
var newSourceValue;
if (sourceValue != '555-55-5555') {
/* 2. Update the new source value as per your need */
newSourceValue = "your_new_source_value";
return newSourceValue;
} else {
return sourceValue ;
}
})(source);
So source value will be look as like below :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates