Assignment rule scripting based on Central time

Sohini Kar
Tera Expert
Routing Requirement:
  • All incidents and requests for type "corporate" received between 6:00 AM and 5:00 PM Central Time should be assigned to: Group1
  • Any requests outside of this time window should be assigned to: Group2

I created two assignemnt groups. But the incident raised through record producer is getting assigned to Group 1 only even though I am raising the request on outside business hours. Can someone help me with the exact script?

 

I used this script, but it is not giving correct result:

(function() {

var nowCT = new GlideDateTime();

nowCT.setTZ('America/Chicago');

var hour = parseInt(nowCT.getHourLocal());

 

return (hour < 6 || hour > 17);

})();

8 REPLIES 8

It is still not working. It is getting assigned to Group 1. Even though currently it is outside business hours hence it should be assigned to group 2.

@Sohini Kar 

run this script in background script and share the results

are you using schedule logic or the 2nd script

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "CET");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime);

var hours = gdtConvertedDateTime.toString().split(' ')[1].split(":")[0];
if (hours >= 6 && hours <= 17) {
    // within business hours
    gs.info('within business hours');
} else {
gs.info('outside business hours');
}
Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

The background script is saying within business hour, but it is still 20 minutes left for 6am in CET time.

I am using 2nd script.

@Sohini Kar 

got it, you want central time, I thought CET which is Europe

update script as this -> use CST instead of CET

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "CST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime);

var hours = gdtConvertedDateTime.toString().split(' ')[1].split(":")[0];
if (hours >= 6 && hours <= 17) {
    // within business hours
    gs.info('within business hours');
} else {
gs.info('outside business hours');
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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