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 detect weekend days

nancyhz
Mega Contributor

I got a requirement -all incident are opened during weekend , their State field must be set to "New".     However, their State value -"New" must be converted to "Active" if date is coming to Weekday (Monday - Friday).     How can I monitor the date change among Weekend to Weekday?

14 REPLIES 14

Atul Kumar2
Giga Guru

Hi Nancy,



I believe you will have to create scheduled jobs and you will have create a script into that and based on that it will change the value in the backed.



Regards,


Atul Kumar


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I would make a Schedule with the the weekends etc. and then make a Before Insert BR that checks if the date is within the schedule(weekdays) or outside(weekend) and depending on value it will set new or active. The have a schedule job each morning making the same check and turning the "new" to "active" if it's a weekday


That schedule perhaps already exists and used by the SLA.



don't know if the first part is needed for you thou.



//Göran


srinivasthelu
Tera Guru

Hi Nancyz,



A Before Business rule with Below code should do.



var dateTime=new GlideDateTime();


var day=dateTime.getDayOfWeekLocalTime();



if(day==6 || day==7){


current.incident_state=1;   // New State value


}


else{


current.incident_state=2; // Active state value


}




More on wiki here GlideDateTime - ServiceNow Wiki


Thanks, Srinivas for your suggested codes.   We are using "us eastern time zone"   as default system time for all date time calculation.   can I still use "getDayOfWeekLocalTime();"?