If start time of Change is in business hours, a new mandatory field needs to display.

StewartFletcher
Tera Expert

We have a requirement on Change Requests, that a new mandatory field be visible to users if they select a state time for their Change that is within business hours. I know how to set this to appear Mon-Fri, but I need to be able to also get it to only show if they select the start time as being between 08:00 and 18:00 Mon-Fri. How would I achieve this with a Client Script please?

22 REPLIES 22

Tried this and get this error on the Planned Start Date field  -: onChange script error: TypeError: id.indexOf is not a function function () { [native code] }


This appears immediately as you open a Change Request, and the u_workinghours field is visible at all times, instead of being hidden.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @StewartFletcher 

 

Try like this in UI policy

AGLearnNGrow_0-1711616167837.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

This seems to conflict with an existing Client Script that validates that the input start date/time is before the end date and throws up errors similar to everyone elses suggestions.

StewartFletcher
Tera Expert

Any other ideas anyone? The planned start date field is a Date/Time field.

 

When using a UI Policy to go off Mon-Fri, it works. As soon as you try to trend on the time, it errors and gives this -:

onChange script error: TypeError: userDate.getHour is not a function function () { [native code] }

 

Scripts above just do not work at all

 

No Client Scripts have anything like this in them, nor Script Includes, UI Pols or Business Rules have this that would relate to Change...

  The following code would be sufficient to fulfill your requirement.
 
var givenDate = new Date(newValue);
var dayOfWeek = givenDate.getDay();
var hours = givenDate.getHours();
 if (dayOfWeek > 0 && dayOfWeek < 6 && hours >= 8 && hours <= 18){
       g_form.setMandatory('field_name',true);
 }