Create a report for RITMs closed on last working day
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 11:49 PM
Hi All,
I need to create a report which should reflect all the RITM details ( list view ) 'closed' on the last working day.
Ex. If 'Friday' is the last working day then the report should show all those RITMs
It'll be great if someone could help me out
Thanks and Regards,
Saurabh Chatterjee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 02:51 AM
classless script include getting called from report condition doesn't support logging.
So you can't test it from reports
Try to test your script include code from background script and then include in classless script include function
Can you share your complete code?
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
01-07-2025 03:13 AM - edited 01-07-2025 03:15 AM
Yes please find the attached code -
gs.info("Inside the script...");
function getLastWorkingDay() {
var today = new GlideDateTime();
var dayOfWeek = today.getDayOfWeek(); // Returns 1 (Sunday) to 7 (Saturday)
var lastWorkingDay = new GlideDateTime(today);
// If today is Monday, subtract 3 days (i.e., Friday)
if (dayOfWeek == 1) {
lastWorkingDay.addDaysUTC(-3);
}
// If today is Sunday, subtract 2 days (i.e., Friday)
else if (dayOfWeek == 7) {
lastWorkingDay.addDaysUTC(-2);
}
// For any other weekday (Tuesday to Saturday), subtract 1 day
else {
lastWorkingDay.addDaysUTC(-1);
}
//Converting to Date Format
var gdt = new GlideDateTime(lastWorkingDay);
var date1 = gdt.getDate();
gs.info("Date1::: " + date1);
var sysId = gs.getProperty('catItem');
var arr = [];
var gr1 = new GlideRecord("sc_req_item");
gr1.addQuery('cat_item', sysId);
gr1.addQuery('closed_at', 'date1');
gr1.query();
while (gr1.next()) {
arr.push(gr1.getUniqueValue());
}
gs.info("Values::: " + arr);
return arr.toString();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 04:15 AM
this line I updated
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
01-06-2025 12:37 AM
Hi @chatsaurav19 ,
create a schedule job which runs on week days and use below code to calculate last working day.
// Function to get the last working day
function getLastWorkingDay() {
var today = new GlideDateTime();
var dayOfWeek = today.getDayOfWeek(); // Returns 1 (Sunday) to 7 (Saturday)
var lastWorkingDay = new GlideDateTime(today);
// If today is Monday, subtract 3 days (i.e., Friday)
if (dayOfWeek == 1) {
lastWorkingDay.addDaysUTC(-3);
}
// If today is Sunday, subtract 2 days (i.e., Friday)
else if (dayOfWeek == 7) {
lastWorkingDay.addDaysUTC(-2);
}
// For any other weekday (Tuesday to Saturday), subtract 1 day
else {
lastWorkingDay.addDaysUTC(-1);
}
return lastWorkingDay;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 02:00 AM
Hi @Runjay Patel ,
Thank you for the script! May I know how to set the same in reporting view, where I need to see the list based on a specific Catalog Item?
Thanks and Regards,
Saurabh Chatterjee