custom approval email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have created a custom approval email notification for a specific catalog item, and I want to disable the OOB approval email for that catalog item which is on sysapproval_approver.
Below is the script that I tried but it blocked notification for all catalog item approvals.
Any help will be appreciated.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @panchbhaic
Please replace if part of code with below logic and give it a try
if (current.sysapproval && current.sysapproval.sys_class_name == "sc_req_item") {
var ritm = current.sysapproval.getRefRecord();
// Check if this is the USB Access request (adjust the condition as needed)
if (ritm && ritm.cat_item == usbFormSysId) {
answer = false;
}
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @panchbhaic ,
In notifications (and business rules with condition scripts), ServiceNow expects the script to return a boolean (true = condition passes / notification fires, false = condition fails / suppressed).
If you just set answer but don’t explicitly return it, behavior can vary:
Sometimes it works because the engine picks up the global answer variable.
Sometimes it doesn’t, especially in self-invoking functions like your last example ((function(){ ... })();), because the scope of answer may not bubble up.
If you keep the self-invoking function, you must return answer:
(function() {
var answer = true; // default: suppress
var usbFormSysId = "3286631f1b9f021005cefc8e034bcbd5";
if (current.approval_for && current.approval_for.getTableName() === "sc_req_item") {
var ritm = current.approval_for.getRefRecord();
if (ritm && ritm.cat_item == usbFormSysId) {
answer = false; // allow for this item
}
}
return answer;
})();
Or if you don’t need the wrapper, just do:
answer = true;
var usbFormSysId = "3286631f1b9f021005cefc8e034bcbd5";
if (current.approval_for && current.approval_for.getTableName() === "sc_req_item") {
var ritm = current.approval_for.getRefRecord();
if (ritm && ritm.cat_item == usbFormSysId) {
answer = false;
}
}
Try above options and I hope this should work.