Send Follow-up Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:47 AM - edited 11-24-2023 06:53 AM
Hi,
@Ankur Bawiskar @Community Alums @Ratnakar
I have a scenario when 'State' is 'InProgress' for 10days , scheduled job should trigger notification to team. I have created four custom True/False fields in the table i.e. Follow-up 1, Follow-up 2, Follow-up 3 and Follow-up 4. Once the team get notified as These are all the cases still 'InProgress' then team manually mark Follow-up 1 as true, again 10 days after the 1st follow-up if the state is still 'InProgress' then it should trigger 2nd follow-up and team manually mark the Follow-up2 and update the case. Likewise it continue until 4th follow-up. And also it should check day if it is Saturday and Sunday it should not trigger notification instead of that it should mark the record for 'Monday Notification'. Notification Should send only on Weekdays.
I have created Scheduled Job but it keeps on running in the loop and Follow-up 1 only working. Can anyone check the script
var gdToday = new GlideDateTime(); // get current date
var day = gdToday.getDayOfWeekUTC(); // get the week day numeric value
var gr1 = new GlideRecord('case');
gr1.addQuery('state', 'In Progress');
gr1.addQuery('inprogress_time', '!=', ' ');
gr1.addQuery('inprogress_time', '>=', gs.daysAgoStart(10));
gr1.query();
var recordFor10Days = [];
while (gr1.next()) {
if (gr1.getValue('follow_up_1') == 0) {
if (day == 6 || day == 0) {
gr1.setValue('monday_notification', true);
gr1.update();
} else if ((day == 1 || day == 2 || day == 3 || day == 4 || day == 5)) {
recordFor10Days.push(gr1.getValue('sys_id'));
}
}
}
if (recordFor10Days.length > 0) {
gs.eventQueue("x_snc_caase.ForFollowup", '', '', recordFor10Days, '1');
}
var gr2 = new GlideRecord('case');
gr2.addQuery('state', 'In Progress');
gr2.addQuery('inprogress_time', '!=', ' ');
gr2.addQuery('inprogress_time', '>=', gs.daysAgoStart(20));
gr2.query();
var recordFor20Days = [];
while (gr2.next) {
// // Check for 20 days if the 2nd notification needs to be sent
if (gr2.getValue('follow_up_2') == 0) {
if (day == 6 || day == 0) {
gr2.setValue('monday_notification', true);
gr2.update();
} else if ((day == 1 || day == 2 || day == 3 || day == 4 || day == 5)) {
recordFor20Days.push(gr2.getValue('sys_id'));
}
}
}
if (recordFor20Days.length > 0) {
gs.info("followup2");
gs.eventQueue("x_snc_case.ForFollowup", '', '', recordFor20Days, '2');
}
var gr3 = new GlideRecord('case');
gr3.addQuery('state', 'In Progress');
gr3.addQuery('inprogress_time', '!=', ' ');
gr3.addQuery('inprogress_time', '>=', gs.daysAgoStart(30));
var recordFor30Days = [];
while (gr3.next()) {
// Check for 30 days if the 3rd notification needs to be sent
if (gr3.getValue('follow_up_3') == 0) {
// For 30 days
if (day == 6 || day == 0) {
gr3.setValue('monday_notification', true);
gr3.update();
} else if ((day == 1 || day == 2 || day == 3 || day == 4 || day == 5)) {
recordFor30Days.push(gr3.getValue('sys_id'));
}
}
}
if (recordFor30Days.length > 0) {
gs.info("followup3");
gs.eventQueue("x_snc_case.ForFollowup", '', '', recordFor30Days, '3');
}
//Final Notification
var gr4 = new GlideRecord('case');
gr4.addQuery('state', 'In Progress');
gr4.addQuery('inprogress_time', '!=', ' ');
gr4.addQuery('inprogress_time', '>=', gs.daysAgoStart(40));
gr4.query();
var recordFor40Days = [];
while (gr4.next()) {
if (gr4.getValue('follow_up_4') == 0) {
if (day == 6 || day == 0) {
gr4.setValue('monday_notification', true);
gr4.update();
} else if ((day == 1 || day == 2 || day == 3 || day == 4 || day == 5)) {
recordFor40Days.push(gr4.getValue('sys_id'));
}
}
}
if (recordFor40Days.length > 0) {
gs.eventQueue("x_snc_case.ForFollowup", '', '', recordFor40Days, '4');
}
Can anyone help me on the script part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:08 AM
Hi @Balaji Munusamy ,
getDayOfWeekUTC() method is returning days from 1 to 7 (Monday being 1).
You are using day 0 which is not existing.
if (day == 6 || day == 0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:15 AM
Hi @IronPotato ,
That's fine but the issue is 'Follow-up 1' condition i.e. recordFor10days only executing others are not executing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:43 AM
After it is triggered it returns 2 cases