ITSM

SamrudhiK
Tera Contributor

I have requirement where a catalog item 'After hours support' form should be only visible outside of working hours i.e. It should be only visible between 5pm EST and 8 am EST. After 8am link should not be visible on portal till 5pm. Can you suggest how to do it ? 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@SamrudhiK 

you can create a User Criteria with script and use Schedule script

Then add this User Criteria in "Available For" related list of your catalog item

// Get current time in UTC
var gdt = new GlideDateTime();

// Convert UTC to EST (Eastern Standard Time)
// EST is UTC-5; adjust for daylight saving if necessary
// For robust handling, use GlideDateTime's setTZ method if your instance supports it
gdt.setTZ('America/New_York'); // This will handle EST/EDT automatically

var hour = parseInt(gdt.getHourLocalTime(), 10);

// Allow access if time is 5pm (17) or later, or before 8am (8)
if (hour >= 17 || hour < 8) {
    answer = true;
} else {
    answer = false;
}

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@SamrudhiK 

you can create a User Criteria with script and use Schedule script

Then add this User Criteria in "Available For" related list of your catalog item

// Get current time in UTC
var gdt = new GlideDateTime();

// Convert UTC to EST (Eastern Standard Time)
// EST is UTC-5; adjust for daylight saving if necessary
// For robust handling, use GlideDateTime's setTZ method if your instance supports it
gdt.setTZ('America/New_York'); // This will handle EST/EDT automatically

var hour = parseInt(gdt.getHourLocalTime(), 10);

// Allow access if time is 5pm (17) or later, or before 8am (8)
if (hour >= 17 || hour < 8) {
    answer = true;
} else {
    answer = false;
}

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

Mark Manders
Mega Patron

Run 2 scheduled jobs at the specific time to activate/deactivate the item.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark