Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

SeeviceNow User Profiles Need To Show Business Hours and Non Business Hours

ysudileti
Tera Contributor

Hi,

 

I have a requirement to show the business hours and non business hours in User profiles based on country Name.

Ex. We have 3 countries User Profiles
1. UK   9 AM to 6 Pm (UK Time)

2. Australia   8 AM to 6 PM AEST

3. Japan 9 AM to 6 PM

for Business hours we need highlight with green. Non business hours red.

Please refer the screenshot for reference.

Could you please guide someone how to implement this one.

 

Thanks,

Yamini

 

 

 

 

 

 

2 REPLIES 2

Vikram Reddy
Tera Guru

Hi @ysudileti,

 

There's no OOB "business hours" indicator on the User form, so this is a small build on top of the native Schedule engine rather than a hunt for a hidden setting. Create one record per country on cmn_schedule (Schedule): "UK Business Hours" on the Europe/London time zone, "Australia Business Hours" on Australia/Sydney, "Japan Business Hours" on Asia/Tokyo, each with a 9 to 6, Monday to Friday Schedule Span (cmn_schedule_span) child record. Schedules carry their own time zone, so you're not doing manual UTC math anywhere. Resolve which schedule applies to a user from their Country field, either in a small lookup script or a reference field you add for it.

For the live check, use the server-side GlideSchedule API: new GlideSchedule(scheduleSysId).isInSchedule(new GlideDateTime()) returns true or false against the schedule's own time zone. Put that logic in a Script Include and call it via GlideAjax from a UI macro (or a Service Portal/UX widget) when the form loads, then render the green or red pill client-side off the response. One thing worth flagging: sys_ui_style (Formatting > Styles) only colors list rows and cells, it has no effect on form fields, so it won't get you the badge from your screenshot on its own, the custom macro is what actually draws it.

 

Thank you,
Vikram Karety
Octigo Solutions INC

vijaydodla
Giga Guru

To implement a dynamic business hours indicator on the User Profile based on the user's country, you need to combine Schedules, a Custom Field, Field Styles (for the green/red colors), and a Client Script with a Script Include to calculate the time dynamically without saving transient data to the database.

ServiceNow's GlideSchedule API is perfect for this because it automatically handles time zone conversions and daylight savings based on the country's schedule.