Clients Script

Phani Pasupulet
Tera Contributor

In my form I have a date field 

when the user filled the date field 

I need to compare with the current date  in client scripts 

filled date should be greater than current date 

can anyone help please.....?

2 ACCEPTED SOLUTIONS

Sagar Pagar
Tera Patron

Hi @Phani Pasupulet,

 

I would suggest to use UI policy instead of Client scripts.

 

Conditions:

Date_field AT OR BEFORE Today

 

Execute of true:

function onCondition() {
g_form.clearValue("date_field");
g_form.showFieldMsg("date_field", "Date should be greater than today" , "error");
}

 

Execute of false:

function onCondition() {
g_form.hideFieldMsg("date_field");
}

 

// added date_field in hidefieldMsg() fucntion

 

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

Anurag Tripathi
Mega Patron
Mega Patron

You can use a simple ui policy to do so

AnuragTripathi_0-1690968056371.png

 

Instead of current minute you can also use today id that works better for you.

Then you can use the script or ui policy action to add alert or change fields as needed.

 

-Anurag

View solution in original post

6 REPLIES 6

Sagar Pagar
Tera Patron

Hi @Phani Pasupulet,

 

I would suggest to use UI policy instead of Client scripts.

 

Conditions:

Date_field AT OR BEFORE Today

 

Execute of true:

function onCondition() {
g_form.clearValue("date_field");
g_form.showFieldMsg("date_field", "Date should be greater than today" , "error");
}

 

Execute of false:

function onCondition() {
g_form.hideFieldMsg("date_field");
}

 

// added date_field in hidefieldMsg() fucntion

 

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

Hello @Sagar Pagar ,

 

How can we restrict user to submit the form in above conditions.

Hi @Deepak89,

 

You can use return false; to avoid form submission at any client side scripts.

 

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

The world works with ServiceNow

Hello @Sagar Pagar ,

 

correct we can add return false at client side but above at  True condition of UI Policy how can i restrict user to submit form in same script.

Execute of true:

function onCondition() {
g_form.clearValue("date_field");
g_form.showFieldMsg("date_field", "Date should be greater than today" , "error");
}