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

Thank you @Abhijith322 that worked when I added in setVisible too, and also an 'else' condition to have them false.

 

However now realising the other issue - So if the end date of it goes over business hours, it needs to trigger this mandatory field. For instance if it starts 7am Monday and ends 8am Monday, it won't trigger which is correct. If it starts 7am Monday and ends 10am Monday, it WILL trigger which ijs correct.

 

However if it starts 7am Monday and ends 9pm Monday for instance, it doesn't trigger, but needs to.


Thoughts?

In short, you need to show the field whenever the implementation window fall in the business hours. Isn't it? 

Correct, yes

StewartFletcher
Tera Expert

So this is the script I have currently, runs onChange on the start_date field -:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    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('u_workinghours', true);
        g_form.setVisible('u_workinghours', true);
    } else
        g_form.setMandatory('u_workinghours', false);
    g_form.setVisible('u_workinghours', false);
}
 
This works when you select a start time that is within business hours, it makes the new field mandatory. When it's out of business hours, the field doesn't show. That's perfect.
 
However for example, if a start time of 19:00 is selected on a Monday, and end time is 11:00 on the Tuesday, that's encroaching into business hours and so needs to bring that field up. Currently it won't.
 
Any thoughts on how we'd achieve this?

StewartFletcher
Tera Expert

Any thoughts community?