How to restrict user to select only 3days from date of request?

Sachin G K1
Kilo Sage

I have date field in catalog item, i need to restrict user to select only any of the date within 3 days from date of request.

And also wish to restrict user in selecting previous date from current date.

 

 

 

 

Thanks in Advance

4 REPLIES 4

Community Alums
Not applicable

Hello @Sachin G K1 ,

 

For the date validations, you can refer this article.

 

If this solves your query, mark this as helpful and correct.

 

Regards

Anand

manjusha_
Kilo Sage

@Sachin G K1 

 

1.You have to use addDays() method to add 3 days in  current date field and check diff, if diff is more than 3 clear the date value and add field error message.

2.To avoid previous date to be selected use gs.dateDiff() method if diff is -1 then the selected date will be past so you can throw field error message

Refer below link-

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594663

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Sachin G K1 

you can use UI policy with no scripting.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sagar Pagar
Tera Patron

Hi @Sachin G K1,

You have to use the UI policies for this.

 

UI policy Condition 1: Date variable BEFORE Today

Execute if true:

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

 

UI policy Condition 2: Date variable RELATIVE after 3 days From now

Execute if true:

function onCondition() {
g_form.clearValue("date_variable");
g_form.showFieldMsg("date_variable", "Date variable date should be not be more than 3 days from now, "error");
}

 

Thanks,
Sagar Pagar

The world works with ServiceNow