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

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Just to be sure you have selected the send to when is selected as event is fired and the event name is your event name:-

 

Saurav11_0-1666161675316.png

 

Also you have the send to par1 and send to par 2 checkbox ticked

 

Saurav11_1-1666161816399.png

 

Please mark answer as correct based on Impact

I already they're being checked and i can see on event logs parm1 and parm2 values getting captured. 

Click on preview notification at the top of the notification and see if the notification is correctly appearing or you are seeing some error which will mean the body of the notification is not correct.

 

Also go to email under system logs and check if the you see the email over there:-

 

Saurav11_0-1666163130746.png

 

And what is the type of it:-

Saurav11_1-1666163157140.png

 

Please mark my answer as correct based on Impact.

I have already verified all this. I can see email notification appearing correctly and when I try to trigger through record insert or update, it's working fine. The only issue is when I try to trigger through an event, it's not getting triggered. I can see the event is getting triggered on event logs with parm1 and parm2 values, but when I try to verify on email logs, it's not showing any emails 

Also hopefully your ID is not the parameter 1 and 2, if they are you will also have to check the below

 

Saurav11_0-1666165620512.png

 

Please mark my answer as correct based on Impact.