- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 08:06 AM
want to get total number of days from today to date incident 'created'
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '4728cc7587f81110872b40cf8bbb3543');
incidentGR.query();
if (incidentGR.next()) {
var today = new GlideDate();
var endDate = incidentGR.sys_created_on.getDisplayValue().split(' ')[0];
var diff = GlideDate.subtract(today, endDate);
var days = diff.getRoundedDayPart();
gs.info(day);
}
ERROR im getting
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 09:17 AM
Hi,
update as this
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '4728cc7587f81110872b40cf8bbb3543');
incidentGR.query();
if (incidentGR.next()) {
var today = new GlideDateTime();
var endDate = new GlideDateTime(incidentGR.sys_created_on);
var diff = GlideDateTime.subtract(today, endDate);
var days = diff.getRoundedDayPart();
gs.info(day);
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 08:09 AM
Hello,
What issues are you seeing, what errors are you getting?
What does your info log statement say?
Please give more information from your end to show what analysis you've done.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 09:09 AM
Try below code:
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 10:38 AM
This didn't work for you?
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 09:17 AM
Hi,
update as this
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '4728cc7587f81110872b40cf8bbb3543');
incidentGR.query();
if (incidentGR.next()) {
var today = new GlideDateTime();
var endDate = new GlideDateTime(incidentGR.sys_created_on);
var diff = GlideDateTime.subtract(today, endDate);
var days = diff.getRoundedDayPart();
gs.info(day);
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader