Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to created report of incidents opened between last Friday of previous month and 10 days prior ?

Divyesh Thakur
Tera Contributor

On the first of each month, I need a report to show the P1 incident records which was opened between the last Friday of the prior month and  10 days prior to that date. Any assistance would be appreciated.

3 REPLIES 3

luffy3478
Tera Guru

List filter : sys_id is one of javascript&colon;<script_include>

 

write your logic inside the client callable script include

maroon_byte
Mega Sage

Using below link, I came up with below script:

https://www.servicenow.com/community/developer-forum/get-last-weekday-quot-x-quot-of-month/td-p/1522...

 

 

var dayOfWeek_toLookFor = 5; // Friday
var dayOfMonth_toLookFor = 0; // Initializer
// Get last day of the month weekday (Sun=0,Mon=1,Tue=2,Wed=3,Thu=4,Fri=5,Sat=6)
var endOfMonth_weekDay = new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDay();
// Get the current weekday (Sun=0,Mon=1,Tue=2,Wed=3,Thu=4,Fri=5,Sat=6)
var current_weekDay = new Date().getDay();
// Get the last day of the month as a number (28,29,30,31)
var daysInMonth =   new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate();
// Get current day of the month (1-31)
var current_dayOfMonth =   new Date().getDate();
if (endOfMonth_weekDay == dayOfWeek_toLookFor) // If last day of month is the dayOfWeek_toLookFor, job done
       dayOfMonth_toLookFor = daysInMonth;
else if (endOfMonth_weekDay > dayOfWeek_toLookFor)
       dayOfMonth_toLookFor = daysInMonth - (endOfMonth_weekDay - dayOfWeek_toLookFor);
else if (endOfMonth_weekDay < dayOfWeek_toLookFor)
       dayOfMonth_toLookFor = daysInMonth - (7 - (dayOfWeek_toLookFor - endOfMonth_weekDay));
var lastMonthLastFri = new Date(new Date().getFullYear(), new Date().getMonth() - 1, dayOfMonth_toLookFor);
var tenDaysBefore = new Date(new Date().getFullYear(), new Date().getMonth() - 1, dayOfMonth_toLookFor - 10);
gs.info(lastMonthLastFri);
gs.info(tenDaysBefore);
 
*** Script: Fri Mar 29 2024 00:00:00 GMT-0700 (PDT)
*** Script: Tue Mar 19 2024 00:00:00 GMT-0700 (PDT)

Hi, Thank you for your prompt reply.
I have added the above code in client callable script include but here it's showing an error. I will attach below the screenshot of the script include as well for reference.