- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 07:42 AM
Hello,
I have created onBefore Transform Script to update target fields in certain conditions for example :
// If type is "A" & discovery is "B" --> Update only the target field discovery
if (source.u_type == "A" && target.discovery == "B") {
target.discovery = "A";
}
When I test, I find that in the target record, all fields are updated but I want only the "discovery" field to be updated.
So how can I ignore the update of the other fields in the Field Maps section and only update one field "discovery" ?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:54 AM
Hi,
There is only one way to achieve this, you will have to update target record in onBefore script and mark ignore as true.
Please try below script,
if (source.u_type == "A" && target.discovery == "B") {
target.discovery = "A";
target.update();
ignore=true;
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 11:34 AM
Hello
you may plan to write two "On before" script with different order as shown below
1) First on-before script - Order as 100
// If type is "A" & discovery is "B" --> Update only the target field discovery
if (source.u_type == "A" && target.discovery == "B") {
target.discovery = "A";
}
2) Second on-before script - Order as 200
if (target.discovery == "A") {
ignore=true;
}
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 07:19 AM
Hello,
It didn't work, the update was ignored.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 07:27 AM
Hi, You can change your code as like below.
if (source.u_type == "A" && target.discovery == "B")
{ target.discovery = "A";
}else {
ignore = true;
}
Please mark as correct answer if it helped.
Regards,
Suresh.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 07:37 AM
Hello,
It's about the first condition if it's true I want to only update target.discovery and ignore the rest of fields.
I don't think the else is the solution, if I add it I won't be able to update fields if (source.u_type != "A" || target.discovery != "B" ) because I still have other conditions to manage.