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

I have already corrected the encoded query.

 

Let me try this email script because mine is not working as per the expectation.

 

Thanks

Still its not printing the correct email body. Email body is blank completely.

Email script is not working at all. Its not printing any body msg based on conditions. Also i have corrected === to == in the script but still its not working.