UI Policy

Mark Wood
Tera Contributor

Hello Experts,

I have a requirement where the user should not be able to select a date that is less than 5 days from the current date. The date should be at least today's date plus 5 days.

If the selected date is greater than or equal to today + 5 days, the user can proceed. Otherwise, a message should be displayed stating that the date cannot be earlier than today + 5 days.

To achieve this, I have configured a UI policy, but it is not working as expected. The pending response should be relative to 5 days from now.

I have attached a screenshot of my UI for your reference.

Thank you.

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

@Mark Wood,

 

A couple of check points on the UI policy... have you set the message to appear to the user in the 'Execute if true' script or of 'Execute if false' script section?

 

Another area is to ensure if the 'Reverse if false' checkbox is ticket in the 'When to apply tab'.

 

I would personally set if so the condition to relative and 'before' 5 days from now, and put the message to the user in the 'Execute if true' script as follows:

 

g_form.clearValue('date'); //change 'date' to your field name ensuring it's within the quotes
g_form.showFieldMsg('date', 'Please ensure that the date is at least 5 days) in the future ', 'error'); //change 'date' to your field name ensuring it's within the quotes

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

View solution in original post

5 REPLIES 5

Mayur2109
Kilo Sage
Kilo Sage

Hi @Mark Wood ,

 

Please refer below community post for your problem.

https://www.servicenow.com/community/developer-forum/variable-date-no-less-than-5-business-days/m-p/... 

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,
Mayur Shardul

ServiceNow Rising Star 2024

Robbie
Kilo Patron
Kilo Patron

@Mark Wood,

 

A couple of check points on the UI policy... have you set the message to appear to the user in the 'Execute if true' script or of 'Execute if false' script section?

 

Another area is to ensure if the 'Reverse if false' checkbox is ticket in the 'When to apply tab'.

 

I would personally set if so the condition to relative and 'before' 5 days from now, and put the message to the user in the 'Execute if true' script as follows:

 

g_form.clearValue('date'); //change 'date' to your field name ensuring it's within the quotes
g_form.showFieldMsg('date', 'Please ensure that the date is at least 5 days) in the future ', 'error'); //change 'date' to your field name ensuring it's within the quotes

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

Mark Wood
Tera Contributor

Hello @Robbie 

Everything is working fine. Could you explain why you're checking for 'before 5 days from now' and how this condition functions? Could you simplify it for me?

Thanks.

Hi @Mark Wood,

 

So there are a few factors to consider with UI Policies when implementing scripting, most notably when you want the script to trigger - either 'Execute when true' or 'Execute when false'.

 

Typically, when scripting in all area's (Client Scripts, Business Rules and Script Includes etc), I always try to tackle or trigger a script with the smaller result set - however, the date will always need to be checked regardless of what date you select.

The main reason however is there is a checkbox on UI Policies which is called 'Reverse if false'. (Checked by default)

If this is checked, the logic in the Execute when false will be fired if the condition is not met, so it is for that reason I reversed the logic. (You could also uncheck this checkbox)

 

Hopefully this makes sense and I haven't confused you or others. Please shout if you would like more clarification.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie