Need Help with Transform Map Script to Handle Blank Source Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2024 05:45 AM - edited ‎12-13-2024 05:49 AM
- I am trying to write a Run Script for a Transform Map in ServiceNow. The requirement is as follows:
- If the source.u_number field contains a blank value (""), the target field (e.g., number) should remain unchanged.
- If the source.u_number has a valid value (non-blank), it should update the target field with that value.
Here the script
answer = (function transformEntry(source) {
if (source.u_number) {
return source.u_number;
} else {
return undefined;
}
})
(source);
The Problem: This script is not working as expected. When source.u_number is blank, it is still updating the target field with a blank value, which I don't want. The target field should remain unchanged in this case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2024 07:05 AM
Hi @sanjeet1245,
This can easily be managed using a script similar to below.
The 'ignore = true' syntax essentially skips the record if the conditions are met, which in your case is when the number (source.u_number) is blank.
if (source.u_number === ''){
ignore = true;
}
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2024 07:08 AM - edited ‎12-13-2024 07:14 AM
if(source.u_number && source.u_number.trim() !== "")
answer = (function transformEntry(source, target) {
if (source.u_number && source.u_number.trim() !== "") {
return source.u_number;
}
return target.number;
})(source, target);