PA script returning NaN for ageing ticket for ritm excluding weekends and holidays
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:29 AM
Hello,
I am getting 'Nan' error for a script (pa_scripts). I have written this script to exclude weekends and holidays and added as a breakdown through breakdown mapping in indicator.
Please let me know why I am getting below error and whether I am going correct as per the requirement mentioned above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:35 AM
try this-> are you sure the record has both open and closed date?
var businessDuration = function(open, closed) {
var startDate = new GlideDateTime(open);
var endDate = new GlideDateTime(closed);
var schedule = new GlideSchedule();
schedule.load('090eecae0a0a0b260077e1dfa71da828'); // sys_id of cmn_schedule
var duration = schedule.duration(startDate, endDate);
// Convert duration to days
var durationInDays = duration.getNumericValue() / (24 * 60 * 60 * 1000);
return durationInDays;
};
var duration = businessDuration(current.opened_at, current.closed_at);
gs.info('Business duration: ' + duration);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:47 AM
Hi Ankur,
I corrected it with your suggested script but this time I got undefined.
Error during JavaScript evaluation com.snc.pa.dc.ScriptException: JavaScript evaluation returned: Undefined in script.
Yes I have taken facts table as sc_req_item which has closed field as well and opened .Below is the screenshot of the PA script .
Do I need to use closed_at or score_end, any idea about this? Earlier I was using score end but then it gave me error for using current has no arguments passed.
Thanks,
Harsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:49 AM
Below is the new script for which I got undefined error as mentioned .