Email notification not getting triggered

JRY
Mega Guru

Hi All,

 

I'm trying to trigger email notification through an event in two different ways. One is business rule and the other way is scheduled job, but there is no luck.

When I'm trying with business rules, I can see the event got triggered but the email notification is not getting triggered. I have verified event logs as I can see values are there on parm1 and parm2 but don't know why it's not getting triggered. Please review the following business rules and assist me in determining what went wrong.

 

 

(function executeRule(current, previous /*null when async*/ ) {
    var userList = [];
    var grAdhoc = new GlideRecord("u_ad_hoc_request");
    grAdhoc.addQuery('parent', current.sys_id);
    grAdhoc.addQuery('state', '1');
    grAdhoc.query();
    if (grAdhoc.next()) {
        grAdhoc.state = '4';
        grAdhoc.update();
        var link = "[code]<a href='" + grAdhoc.getLink() + "'>" + grAdhoc.number + "</a>[/code]";
        var entryJournal = gs.getMessage("Request {0} has been Closed.", [link]);
        current.work_notes = entryJournal;
        current.update();
    }

    var requestedFor = gs.getProperty('dg.requested.for.user');
    var child = new GlideRecord("u_ad_hoc_request");
    child.initialize();
    child.short_description = current.short_description + " - (" + current.u_username + ")";
    child.description = child.short_description;
    child.urgency = "3";
    child.impact = current.impact;
    child.priority = current.priority;
    child.parent = current.sys_id;
    child.assignment_group = "";
    child.assigned_to = "";
    child.requested_for = requestedFor;
    child.opened_by = current.opened_by;
    child.watch_list = current.watch_list;
    child.cmdb_ci = '9672c43adb0e15505ec08b4d13961923';
    child.insert();

    var currentLink = "[code]<a href='" + child.getLink() + "'>" + child.number + "</a>[/code]";
    var journalEntry = gs.getMessage("Facilitation request {0} has been opened and linked to this event.", [currentLink]);
    current.work_notes = journalEntry;
    current.update();
    var watchList = child.watch_list.split(',');
    gs.eventQueue('ad.hoc_notification', child, watchList, gs.getUserDisplayName());


})(current, previous);

 

The second method is scheduled jobs. Here I'm trying to trigger events and notifications based on conditions. When an ad hoc request is created, I need to send one email notification. As you can see in the above business rule, this email notification triggers until a service catalogue request have been created by the manager and we need to send three reminders. If the manager is not submitting the catalogue request, then after the third reminder, we need to send one more email to the other person and stop the scheduled job. I have created 2 fields on ad hoc request, "ritm flag - true/false" and "notification count - integer", and written business rules on ritm whenever a specific catalogue item has been submitted and requested for is the same as AD hoc requested for then set "ritm flag-true" and one more email script has been added to email notification in that I'm checking the count of emails triggered and updating the notification count field value. I have tried the below script, but there's no luck. Can anyone help with how to do this?

 

 

Scheduled Job Condition -
var result = true;
var grAdhoc = new GlideRecord('u_ad_hoc_request');
grAdhoc.addEncodedQuery('u_ritm_flag', false);
grAdhoc.query();
if (grAdhoc.u_notification != 3) {
    result = false;
}
result;

 

 

 

Scheduled Job Run The Script - 
var event = 'ad.hoc_notification';
var grAdhoc = new GlideRecord('u_ad_hoc_request');
grAdhoc.addEncodedQuery('u_ritm_flag', false);
grAdhoc.query();
if (grAdhoc.u_notification < 3) {
    gs.eventQueue('event', grAdhoc, grAdhoc.getValue('watch_list'), '');
} else if (grAdhoc.u_notification == 3) {
    gs.eventQueue('event', grAdhoc, grAdhoc.getValue('requested_for'), '');
}

 

Thanks,

JRY

1 ACCEPTED SOLUTION

Hello,

 

The watchlist is a reference field just pass the watchlist directly it should work fine

 

Please mark my answer as correct based on Impact.

 

View solution in original post

15 REPLIES 15

It's also checked. I have verified the users also having email id and they're active.

Hello,

 

Please check the below articles and see incase if you find any lead:-

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0791868

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0825496

 

Also for your BR can you hardcode sysid of two users in the event queue and check once

 

    gs.eventQueue('ad.hoc_notification', child, 'sysidofuser1', 'sysidofuser2');

 

Please mark my answer as correct based on Impact.

Hi Saurav,

 

When I added hardcoded sys id's, it worked; it got triggered. I may know why it didn't get triggered before. Previously, it was taking the name rather than the sys id. When I added the SYS ID, it worked. Can you help with what needs to change in the script to get sys id's from the watchlist field?

 

Thanks,

JRY

Hello,

 

The watchlist is a reference field just pass the watchlist directly it should work fine

 

Please mark my answer as correct based on Impact.

 

I have tried passing watchlist but it's not working