Schedule job trigerring notification which contains a email script calculating wrong days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-25-2025 03:34 AM - edited ā04-26-2025 03:55 AM
Hi All,
I have a notification which is triggered by a event and that event is triggered by a scheduled job. And also have email script in that notification. If you see the below email script :- Suppose 10 records falls under this notification , it will calculate remaining days to be breached from email triggered date for each record .
The email script working fine but still it is calculating 1 day above for the records. If you see in the attached pictures, I trigged email yesterday but if you calculate, the no. of days will be 1day extra from current date(email triggered date) . I think now it includes either email triggered day or record breached day .I am attaching the current schedule job and email script. I triggered a mail today it's calculating 1 day less for 7 days remaining records. Please help me to resolve the issue .
Thank You,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-26-2025 12:24 AM
Hi @1_DipikaD
May i know your instance time zone?
Also make few changes to your mail script. Currenlty it's picking up the UTC timezone. PFB the modified scripts.
Scheduled job script:
var gr_user = new GlideRecord('u_capacity_reviews');
gr_user.addEncodedQuery('u_status=pending^active=true');
gr_user.query();
while (gr_user.next()) {
var reviewdate = new GlideDateTime(gr_user.u_capacity_review_due_date.toString());
reviewdate.addDaysLocalTime(parseInt(-13));
var duedate = reviewdate.getDisplayValue().split(' ')[0];
var gr_date = new GlideDate();
if (gr_date.getDisplayValue().toString() == duedate.toString()) {
gs.eventQueue('notify.capacity.reviewers', gr_user, gr_user.u_application_instance.u_support_owner, gr_user.u_application_instance.owned_by);
}
var reminder = new GlideDateTime(gr_user.u_capacity_review_due_date.toString());
reminder.addDaysLocalTime(-6);
var duedate2 = reminder.getDisplayValue().split(' ')[0];
var currentDate = new GlideDate();
if (currentDate.getDisplayValue().toString() == duedate2.toString()) {
gs.eventQueue('notify.capacity.reviewers', gr_user, gr_user.u_application_instance.u_support_owner, gr_user.u_application_instance.owned_by);
}
}
Mail script:
(function runMailScript(current, template, email, email_action, event) {
var gr = new GlideRecord('u_capacity_reviews');
gr.addQuery('u_status', 'pending');
gr.addQuery('u_application_instance.u_support_owner', current.u_application_instance.u_support_owner);
gr.query();
if (gr.hasNext()) {
template.print('<table class ="grplist"><tr style="font-size: 9pt; background: rgb(193, 193, 193); border:1pt solid black; text-align: center;"><td style="font-size: 8.5pt; width: 10%;"><strong>Division</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Subdivision</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Number</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Application Instance</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Due Date</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Minimum Review Cycle</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Support Group</strong></td><td style="font-size: 8.5pt; width: 10%;"><strong>Days until Breach</strong></td></tr>');
}
while (gr.next()) {
var reviewdate = new GlideDateTime(gr.getDisplayValue('u_capacity_review_due_date'));
var reviewdateValue = reviewdate.getNumericValue();
var gdt = new GlideDateTime();
var gdt1 = gdt.getNumericValue();
var dateDiff = reviewdateValue - gdt1; // Still in milliseconds here
var daysDiff = dateDiff / 24 / 60 / 60 / 1000;
var daysDiff1 = Math.floor(daysDiff);
var capacity_number = '<a href="http://' + gs.getProperty("instance_name") + '.service-now.com/u_capacity_reviews.do?sys_id=' + gr.getValue('sys_id') + '">' + gr.u_number + '</a>';
var appinstance = '<a href="http://' + gs.getProperty("instance_name") + '.service-now.com/u_cmdb_ci_app_instance.do?sys_id=' + current.u_application_instance.sys_id + '">' + gr.u_application_instance.name + '</a>';
template.print('<tr><td style="font-size: 8.5pt; width: 10%;">' + gr.u_application_instance.u_division.name + '</td><td style="font-size: 8.5pt; width: 10%; " >' + gr.u_application_instance.u_subdivision.name + '</td><td style="font-size: 8.5pt; width: 10%; " >' + capacity_number + '</td><td style="font-size: 8.5pt; width: 10%;">' + appinstance + '</td><td style="font-size: 8.5pt; width: 10%;">' + gr.getDisplayValue('u_capacity_review_due_date') + '</td><td style="font-size: 8.5pt; width: 10%;">' + gr.u_review_cycle + '</td><td style="font-size: 8.5pt; width: 10%;">' + gr.u_application_instance.u_support_group.name + '</td><td style="font-size: 8.5pt; width: 10%;">' + daysDiff1 + '</td></tr>');
}
template.print('</table>');
template.print('<style>.grplist td{border-spacing: 0pt; padding: 0mm 0mm 0mm .5mm; border:1pt solid black;}</style>');
template.print('<style>.grplist{border-spacing: 0px; border-collapse: collapse; border:1pt solid black;}</style>');
})(current, template, email, email_action, event);
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-28-2025 07:41 PM
No , Still finding