- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 07:20 AM
Trying this code below to generate the days since last major incident. I have the latest being 17 days ago but this generates the following "20,263 Days":
Any thoughts on correcting this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 09:53 AM
After adding some log statements I saw that the script was returning nothing for opened_at. Then I realized you were missing a peace of code. Here is the updated script for that section.
var grIncident = new GlideRecord('incident');
grIncident.addQuery('major_incident_state', 'accepted');
grIncident.orderByDesc('opened_at');
grIncident.setLimit(1);
grIncident.query();
if (grIncident.next()) { //Missing this if statment which tells the system which record to look at to get the data.
var createdDateValue = grIncident.getDisplayValue('opened_at');
// gs.log("Created Date: " + createdDateValue);
var createdDate = new GlideDateTime(createdDateValue);
var currentDate = new GlideDateTime().getLocalDate();
var createdTimeMs = createdDate.getNumericValue();
// gs.log("CreatedTime " + createdTimeMs);
var currentTimeMs = currentDate.getNumericValue();
// gs.log("currentTime " + currentTimeMs);
var timeDiffMs = currentTimeMs - createdTimeMs;
var openDays = Math.floor(timeDiffMs / 86400000);
retun openDays + " Days";
// gs.log(openDays + " Days");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 07:58 AM
Change this line var createdDateValue = grIncident.getValue('opened_at') to var createdDateValue = grIncident.getDisaplyValue('opened_at').
I believe the issue is that getValue will return the backend value of the date/time field which is stored in GMT. Where getDisplayValue will return what is displayed to the user which would be local time.
PS. in the future please use the insert edit code function in the HTML editor of the question you are posting to past the code instead of providing a screenshot. It will make it easier to test your code in our PDI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 08:04 AM
Thanks, still getting the same inaccurate days display. Here is the code:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="jvar_changes" object="true">
//<![CDATA[
(function daysSinceMajor() {
var grIncident = new GlideRecord('incident');
grIncident.addQuery('major_incident_state', 'accepted');
grIncident.orderByDesc('opened_at');
grIncident.setLimit(1);
grIncident.query();
var createdDateValue = grIncident.getDisplayValue('opened_at');
var createdDate = new GlideDateTime(createdDateValue);
var currentDate = new GlideDateTime().getLocalDate();
var createdTimeMs = createdDate.getNumericValue();
var currentTimeMs = currentDate.getNumericValue();
var timeDiffMs = currentTimeMs - createdTimeMs;
var openDays = Math.floor(timeDiffMs / 86400000);
return openDays + " Days";
})();
//]]>
</g2:evaluate>
<h1 style="text-align:center;">$[jvar_changes]</h1>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 09:53 AM
After adding some log statements I saw that the script was returning nothing for opened_at. Then I realized you were missing a peace of code. Here is the updated script for that section.
var grIncident = new GlideRecord('incident');
grIncident.addQuery('major_incident_state', 'accepted');
grIncident.orderByDesc('opened_at');
grIncident.setLimit(1);
grIncident.query();
if (grIncident.next()) { //Missing this if statment which tells the system which record to look at to get the data.
var createdDateValue = grIncident.getDisplayValue('opened_at');
// gs.log("Created Date: " + createdDateValue);
var createdDate = new GlideDateTime(createdDateValue);
var currentDate = new GlideDateTime().getLocalDate();
var createdTimeMs = createdDate.getNumericValue();
// gs.log("CreatedTime " + createdTimeMs);
var currentTimeMs = currentDate.getNumericValue();
// gs.log("currentTime " + currentTimeMs);
var timeDiffMs = currentTimeMs - createdTimeMs;
var openDays = Math.floor(timeDiffMs / 86400000);
retun openDays + " Days";
// gs.log(openDays + " Days");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 10:50 AM
This worked perfect, added in the code line you provided and it is now representing the correct day count.