Scheduled job for approvals expiration

Poorva Bhawsar
Mega Sage

Hi Community,

 

I need to trigger an expiration email based on some conditions.

1. A notification needs to be triggered every day when an approval is expired yesterday along with some other filter conditions.

2. A notification needs to be triggered every 1st of a month when an approval is expiring in a month along with some other filter conditions.

This notifications needs to be triggered to product owner.

 

So, here is my scheduled jobs:

1. 

var app = new GlideRecord('cmdb_ci_business_app');
app.addEncodedQuery("operational_status=1^department.business_unit=a3fa3110dbc6f3405917fac6bf96196c^sys_tags.38372c381bb4e150b447a8aa274bcb0c=38372c381bb4e150b447a8aa274bcb0c^u_last_bia_approvalISEMPTY^ORu_last_bia_approvalRELATIVELT@month@ahead@1");
app.query();
while (app.next()) {
    gs.eventQueue('bia.approval.expiration', app, 'month', '');
}
 
var app = new GlideRecord('cmdb_ci_business_app');
app.addEncodedQuery("operational_status=1^department.business_unit=a3fa3110dbc6f3405917fac6bf96196c^sys_tags.38372c381bb4e150b447a8aa274bcb0c=38372c381bb4e150b447a8aa274bcb0c^u_last_bia_approvalISEMPTY^ORu_last_bia_approvalONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");
app.query();
while (app.next()) {
    gs.eventQueue('bia.approval.expiration', app, 'yesterday', '');
}
 
I have an event registry with the name bia.approval.expiration.
 
I have an email script using which i want to show different email bodies based on the parameters.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var month = event.parm1;
    //if (month) {
        template.print('This email is for bia approval expiring within a month.');
        template.print('<br>');

    //}

    var yesterday = event.parm1;
    //if (yesterday) {
        template.print('This email is for bia approval expired yesterday.');
        template.print('<br>');
    //}

})(current, template, email, email_action, event);
 
But nothing is working. The email is not getting triggered.
Kindly help me to sort it out.
 
Thanks
12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@Poorva Bhawsar 

what debugging you did?

are you sure it went inside the while and triggered the event?

you are not setting the recipient in eventQueue() function, so are you setting it up directly in notification level?

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

Yeah i am setting the recipient directly in the notification.

@Ankur Bawiskar any update on this?

@Poorva Bhawsar 

are you sure it went inside the while and triggered the event?

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