Email Notification Trigger issue

DharmaT
Tera Contributor

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 ...

1 ACCEPTED SOLUTION

@DharmaT 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

DharmaT
Tera Contributor

email Not.png

Abhijit4
Mega Sage

Hi @DharmaT 

 

If you want to put data in key-value pair format then you would need to use json assignment. However, you are trying to do with array I guess. You should be using something like below at line number 12:

 

userTasks[userId]={};

 

If you need further help, please put your script here ( not screenshot ). Also provide details what you are getting in logs?

Regards,

Abhijit 

ServiceNow MVP

ServiceNow Buddy Owner: snbuddy.com

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Robert H
Mega Sage

Hello @DharmaT ,

 

So you are seeing the expected events in the Events [sysevent] table after running this script?

And you have registered "IRM_pending_tasks_reminder" in the Event Registry, and for the User [sys_user] table?

Please show us how you have configured the Notification that listens to this event.

 

Regards,

Robert

Chaitanya ILCR
Kilo Patron

Hi @DharmaT ,

Looks like you are only using the event suffix 

is the even is in global scope in the event registry?

else open the event registry and and copy the name and use that as event name in gs.eventQueue method

 

ChaitanyaILCR_0-1746168929368.png

 

if this doesn't work

please share all the details scheduled jobs and script us have used and screenshots of notification that you have created

 

does the notification has recipients configured and do they have any notification preferences set?

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya