Create a report for RITMs closed on last working day

chatsaurav19
Tera Contributor

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

14 REPLIES 14

@chatsaurav19 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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();
}

 

@chatsaurav19 

this line I updated

gr1.addQuery('closed_at', date1); // date1 should not be in quotes

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Runjay Patel
Giga Sage

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;
}

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?

 

chatsaurav19_0-1736157618475.png

 

 

Thanks and Regards,

Saurabh Chatterjee