- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 11:33 PM
I want to trigger an email notification weekly to assigned person if there is any pending task in the Bin which comes from the table "sn_grc_task ", created the scheduled job while executing able to see the logs thats triggering the job and event but the email is not triggering not able to see in the email logs, created the notification and event in the sys_user table. please help me to fix ...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 01:57 AM
why did you create event in global scope when the sn_grc_task table is in other scope?
Changes below
1) Event should be on sn_grc_task table and in "GRC: Profiles" scope
2) Notification should be on sn_grc_task and and scope "GRC: Profiles"
a) Event Parm1 contains Recipient - True
3) scheduled job script
(function executeRule() {
var gr = new GlideRecord('sn_grc_task');
gr.addEncodedQuery('stateNOT IN3,4,7^assigned_toISNOTEMPTY');
gr.query();
var userTasks = {};
while (gr.next()) {
var userId = gr.assigned_to.sys_id.toString();
if (!userTasks[userId]) {
userTasks[userId] = [];
}
userTasks[userId].push(gr.getDisplayValue('number') + ' - ' + gr.short_description);
}
for (var user in userTasks) {
var taskList = userTasks[user].join('\n');
var taskGR = new GlideRecord('sn_grc_task'); // Use task record as base
taskGR.addQuery('assigned_to', user);
taskGR.query();
if (taskGR.next()) {
gs.eventQueue(
'IRM_Pending_tasks_reminder',
taskGR, // Pass TASK record (not user)
taskGR.assigned_to.toString(), // Proper recipient reference
taskList // Task data parameter
);
gs.info("Queued reminder for: " + taskGR.assigned_to.name);
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 12:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 01:31 AM - edited 05-02-2025 02:18 AM
Hi @DharmaT
You had bit of inefficiencies in your code so I have modified your whole logic to achieve your required output.
Here a working updated script that I created for Incident table for testing purpose:
var gr = new GlideAggregate('incident');
gr.addEncodedQuery('stateNOT IN3,4,7^assigned_toISNOTEMPTY');
gr.groupBy("assigned_to");
gr.query();
while (gr.next()) {
var jsonTicketList=[];
var i=0;
var userId = gr.assigned_to.sys_id.toString();
var grUserIncidents = new GlideRecord('incident');
grUserIncidents.addEncodedQuery('stateNOT IN3,4,7');
grUserIncidents.addQuery("assigned_to",userId);
grUserIncidents.query();
while(grUserIncidents.next()){
jsonTicketList[i++]=grUserIncidents.getValue("number")+"- "+grUserIncidents.getValue("short_description");
}
gs.info("User Id: "+gr.assigned_to.getDisplayValue()+"\nTask Details:\n"+jsonTicketList);
//gs.eventQueue('IRM_Pending_tasks_reminder', userGR,gr.assigned_to, jsonTicketList);
// gs.info("Sending reminder to user: " +userGR.name);
}
Output:
Here is updated script for you to use:
var grGRCTask = new GlideAggregate('sn_grc_task');
grGRCTask.addEncodedQuery('stateNOT IN3,4,7^assigned_toISNOTEMPTY');
grGRCTask.groupBy("assigned_to");
grGRCTask.query();
while (gr.next()) {
var jsonTicketList=[];
var i=0;
var userId = grGRCTask.assigned_to.sys_id.toString();
var grUserIncidents = new GlideRecord('sn_grc_task');
grUserIncidents.addEncodedQuery('stateNOT IN3,4,7');
grUserIncidents.addQuery("assigned_to",userId);
grUserIncidents.query();
while(grUserIncidents.next()){
jsonTicketList[i++]=grUserIncidents.getValue("number")+"- "+grUserIncidents.getValue("short_description");
}
var userGR=grGRCTask.assigned_to.getRefRecord();
gs.info("User Id: "+grGRCTask.assigned_to.getDisplayValue()+"\nTask Details:\n"+jsonTicketList);
gs.eventQueue('IRM_Pending_tasks_reminder', userGR,grGRCTask.assigned_to.toString(), jsonTicketList);
// gs.info("Sending reminder to user: " +userGR.name);
}
Who will receive should be parm1 user and you can use parm2 in email body to show ticket details for users.
If my response helped please mark it as correct.
Regards,
Abhijit
ServiceNow MVP
ServiceNow Buddy Owner: snbuddy.com
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 01:57 AM
why did you create event in global scope when the sn_grc_task table is in other scope?
Changes below
1) Event should be on sn_grc_task table and in "GRC: Profiles" scope
2) Notification should be on sn_grc_task and and scope "GRC: Profiles"
a) Event Parm1 contains Recipient - True
3) scheduled job script
(function executeRule() {
var gr = new GlideRecord('sn_grc_task');
gr.addEncodedQuery('stateNOT IN3,4,7^assigned_toISNOTEMPTY');
gr.query();
var userTasks = {};
while (gr.next()) {
var userId = gr.assigned_to.sys_id.toString();
if (!userTasks[userId]) {
userTasks[userId] = [];
}
userTasks[userId].push(gr.getDisplayValue('number') + ' - ' + gr.short_description);
}
for (var user in userTasks) {
var taskList = userTasks[user].join('\n');
var taskGR = new GlideRecord('sn_grc_task'); // Use task record as base
taskGR.addQuery('assigned_to', user);
taskGR.query();
if (taskGR.next()) {
gs.eventQueue(
'IRM_Pending_tasks_reminder',
taskGR, // Pass TASK record (not user)
taskGR.assigned_to.toString(), // Proper recipient reference
taskList // Task data parameter
);
gs.info("Queued reminder for: " + taskGR.assigned_to.name);
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader