How to implement the same logic in 3 date fields in a form?

Aditya Sinha
Tera Contributor

I have 3 date fields in a form and I have to ensure all of them satisfy the condition that a date of the past cannot be put in them. How do I implement this in the most concise way?

2 ACCEPTED SOLUTIONS

Sagar Pagar
Tera Patron

Hi @Aditya Sinha,

 

 

If you are working with fields, then create UI policy. If you are working with variables, then create Catalog UI policy.

 

Condition as:

Date_field1 is AT OR BEFORE Today

Execute if true:

function onCondition() {
g_form.clearValue("Date_field2");
g_form.showFieldMsg("Date_field2", "Past date not allowed" , "error");
}

 

 

Date_field2 is AT OR BEFORE Today

Execute if true:

function onCondition() {
g_form.clearValue("Date_field2");
g_form.showFieldMsg("Date_field2", "Past date not allowed" , "error");
}

 

Date_field3 is AT OR BEFORE Today

Execute if true:

function onCondition() {
g_form.clearValue("Date_field3");
g_form.showFieldMsg("Date_field3", "Past date not allowed" , "error");
}

 

 

For reference: No Code date validations through (Catalog) UI Policies 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

Hi @Aditya Sinha,

 

Yes. You need to write 3 UI policies for each field.

 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

3 REPLIES 3

Sagar Pagar
Tera Patron

Hi @Aditya Sinha,

 

 

If you are working with fields, then create UI policy. If you are working with variables, then create Catalog UI policy.

 

Condition as:

Date_field1 is AT OR BEFORE Today

Execute if true:

function onCondition() {
g_form.clearValue("Date_field2");
g_form.showFieldMsg("Date_field2", "Past date not allowed" , "error");
}

 

 

Date_field2 is AT OR BEFORE Today

Execute if true:

function onCondition() {
g_form.clearValue("Date_field2");
g_form.showFieldMsg("Date_field2", "Past date not allowed" , "error");
}

 

Date_field3 is AT OR BEFORE Today

Execute if true:

function onCondition() {
g_form.clearValue("Date_field3");
g_form.showFieldMsg("Date_field3", "Past date not allowed" , "error");
}

 

 

For reference: No Code date validations through (Catalog) UI Policies 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Sagar Pagar do I have to write 3 policies, one for each field?

Hi @Aditya Sinha,

 

Yes. You need to write 3 UI policies for each field.

 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow