Scheduled job for approvals expiration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 11:58 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 09:38 PM
I checked adding logs, its not going inside the while loop. I am getting the value of app before while loop but not after entering the while loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 12:11 AM
@Ankur Bawiskar i was able to resolve the issue. The issue was with the encoded query, one filter condition was weird inside that which was not allowing it enter in the while loop.
Now, based on my email script i want to show different email bodies in the email but my email script is not showing any msg in the email body.
Can you plz help me with that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 01:52 AM
you can have email script and handle the logic
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 02:26 AM
I have that script which i have shared above in the question itself but i am not sure about the logic is correct or not?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 07:05 AM
Hi @Poorva Bhawsar ,
Looks like there is an issue with the encodedquery- Please double check
please find the below updated scripts-
Schedule Job 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_approvalONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");
app.query();
while (app.next()) {
gs.eventQueue('bia.approval.expiration', app, 'yesterday', '');
}
Schedule Job 2-
var app = new GlideRecord('cmdb_ci_business_app');
app.addEncodedQuery("operational_status=1^department.business_unit=a3fa3110dbc6f3405917fac6bf96196c^sys_tags.38372c381bb4e150b447a8aa274bcb0c=38372c381bb4e150b447a8aa274bcb0c^u_last_bia_approvalRELATIVELT@month@ahead@1");
app.query();
while (app.next()) {
gs.eventQueue('bia.approval.expiration', app, 'month', '');
}
Ensure you have an event registered with the name bia.approval.expiration
Email Script-
(function runMailScript(current, template, email, email_action, event) {
var param = event.parm1;
if (param === 'month') {
template.print('This email is for BIA approval expiring within a month.');
} else if (param === 'yesterday') {
template.print('This email is for BIA approval expired yesterday.');
}
})(current, template, email, email_action, event);
Also ensure that you have a notification set to be triggered by the event bia.approval.expiration
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar