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

TEJESHBHEEMAVAR
Tera Expert

Try this code,

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

var selectedDate = new GlideDateTime(newValue);
var currentDate = new GlideDateTime();
currentDate.addDays(5);

if (selectedDate < currentDate) {
g_form.showFieldMsg('your_date_field', 'The date cannot be earlier than 5 days from today.', 'error');
g_form.clearValue('your_date_field');
} else {
g_form.hideFieldMsg('your_date_field', 'error');
}
}