Issue with Email Notification and event
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 02:38 AM
Hi All ,
I have a requirement where for my normal change requests it should trigger the function CNC() [in the function I am skipping assigned to and requested by from getting the approval emails ] the event nc.approve.inserted but the below script it is triggering event : nc.approve.inserted for the approvers but for the assigned to and requested by it is triggering the event : approve.inserted , which should not happen .
What changes do I need to make in my below script where it will trigger : nc.approve.inserted for all the approvers except the assigned to and requested by and no events should be triggered for assigned to and requested by .
Script :
function CR() {
var task = current.sysapproval.sys_class_name || current.source_table;
return (task == 'sr');
}
function CST() {
var task = current.sysapproval.sys_class_name || current.source_table;
return (task == 'st');
}
function CSC() {
var task = current.sysapproval.sys_class_name || current.source_table;
return (task == 'scp');
}
function CNC() {
if (current.source_table == 'change_request' || current.sysapproval.sys_class_name == 'change_request') {
var changeSysId = current.document_id;
var assignedto = current.approver.sys_id.toString();
var CR = new GlideAggregate('change_request');
CR.addEncodedQuery("type=Normal^sys_id=" + changeSysId + "^assigned_to=" + assignedto + "^ORrequested_by=" + assignedto);
CR.addAggregate('COUNT');
CR.query();
var count = 0;
if (CR.next()) {
count = CR.getAggregate('COUNT');
}
if (count > 0) {
return false;
} else {
return true;
}
} else
return true;
}
var isRequest = CR();
var isSCTask = CST();
var isStdChange = CSC();
var isnormalchange = CNC();
if (current.state.changes() && current.state == 'requested') {
event = "approve.inserted";
if (isRequest) {
event = "req.approve.inserted";
} else if (isSCTask) {
event = "st.approve.inserted";
} else if (isStdChange) {
event = "scp.approve.inserted";
} else if (isnormalchange) {
event = "nc.approve.inserted";
}
gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
updateTask(current, current.approver.getDisplayValue() + " requested to approve task");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:01 AM
Hi,
In below script you are setting event='approve.inserted', always and then you are proceeding with additional checks. If all if-else conditions fails event is having the value 'approve.inserted' (like default value)
var isRequest = CR();
var isSCTask = CST();
var isStdChange = CSC();
var isnormalchange = CNC();
if (current.state.changes() && current.state == 'requested') {
event = "approve.inserted"; // this line should be conditional
if (isRequest) {
event = "req.approve.inserted";
} else if (isSCTask) {
event = "st.approve.inserted";
} else if (isStdChange) {
event = "scp.approve.inserted";
} else if (isnormalchange) {
event = "nc.approve.inserted";
}
As I am not aware about your use case and current implementation I cannot suggest exact changes. You have to apply some logic considering all scenarios and set event only when it meet particular condition and initially it should be empty.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:15 AM
Hi @Anil Lande - can you please help me with the script which changes you are mentioning about ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:25 AM
You can try below:
var isRequest = CR();
var isSCTask = CST();
var isStdChange = CSC();
var isnormalchange = CNC();
if (current.state.changes() && current.state == 'requested') {
if (!(current.source_table == 'change_request' || current.sysapproval.sys_class_name == 'change_request')) {
event = "approve.inserted"; // this line should be conditional
}
if (isRequest) {
event = "req.approve.inserted";
} else if (isSCTask) {
event = "st.approve.inserted";
} else if (isStdChange) {
event = "scp.approve.inserted";
} else if (isnormalchange) {
event = "nc.approve.inserted";
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:48 AM
Hi @Anil Lande - I tried with the above change but it is triggering now :
nc.approve.inserted"
for all the approvers and it is not skipping the requested by and assigned to also ideally it should skip these two person from approvers.