Check the created time falling in between business hours or not and deciding the SLA Definition.

maheshm
Tera Expert

Hello Folks,

wondering if there is a way to find if a ticket is created in the business hours or not and set a flag based on the output.

 

The requirement goes like this.

Business Hours are 8 30am to 5 30pm.

Incident is created between 8 30am and 5 30pm on Day 1(it can be under any timezone), the flag In Business Hour is TRUE.

if the incident is created after 5 30pm on Day 1 and before 8 30am on Day 2 (next day or next business day), the flag In Business Hour must be FALSE.

 

Based on this flag set, am trying to configure my SLAs that carry different timings for In time and out of business hour schedule.

 

any leads on this ?

 

thanks !

Mahesh.

1 ACCEPTED SOLUTION

I just helped another person w/ a similar issue. See his post:

https://community.servicenow.com/community?id=community_question&sys_id=46fee2f2db8a93444816f3231f96193e

 

Add this to the top of the script:

var ticketTime = <get value of ticket created time>;

ticketTime .add(ticketTime .getTZOffset() * -1);

 

Might help...hopefully

View solution in original post

5 REPLIES 5

matthew_magee1
Giga Guru

Hi Mahesh,

Perhaps something like this if you are looking at it from a business rule perspective:

var ticketTime = <get value of ticket created time>;

var gdt = new GlideDateTime(ticketTime);

gt = gdt.getTime();

var endTime = new GlideTime("17:30:00");

var startTime = new GlideTime("08:30:00");

if(gt < endTime && gt > startTime){

current.in_business_hour = true;

}

else {

current.in_business_hour = false;

}

 

Now if your business hours are M-F, that will have to factored in too

PS: I Haven't tested this yet

Hi Matthew,

 

thanks for stepping in to respond to my query.

 

i see the following error while submitting the incident.

exception: org.mozilla.javascript.EvaluatorException: Cannot convert 17:30:00 to java.lang.Long 

 

Thanks,

Mahesh

Try:

 

var ticketTime = <get value of ticket created time>;

var gdt = new GlideDateTime(ticketTime);

gt = gdt.getTime();

var endTime = new GlideTime();

var startTime = new GlideTime();

startTime.setValue('08:30:00');

endTime.setValue('17:30:00');

if(gt < endTime && gt > startTime){

current.in_business_hour = true;

}

else {

current.in_business_hour = false;

}

Hi Matthew,

 

the script works great with only exception that the time captured for the field is in a different timezone other than the one selected in the instance.

 

is there a way to achieve that as part of this script.

 

thanks,

Mahesh.