Allow user to select end date 3 days greater than end date in catalog item

Misbah Sayyed
Tera Contributor

I have a catalog item, with fields: start date, end date
The end date should always be selected to be 3 days greater than the start date.

Else the form should not be submitted and it should throw error message.

Please help me to achieve this!!

Thanks in advance.

 

@Maik Skoddow @Mark Roethof @Gaurav Shirsat @ghaing  @tltoulson @Ankur Bawiskar @Chuck Tomasi 

 
4 REPLIES 4

Prince Arora
Tera Sage
Tera Sage

@Misbah Sayyed 

 

You can achieve this using the UI policy no code:

 

Please check the below example for the reference:

PrinceArora_0-1683112943113.png

 

Please refer this BLOG  for more info

 

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

 

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Misbah Sayyed ,

 

You can create a onChange catalog client script, the script is as follows:

function onSubmit() {
 
    var startDate = g_form.getValue('start_date');
    var sd = getDateFromFormat(startDate, g_user_date_format);
    var endDate = g_form.getValue('end_date');
    var ed = getDateFromFormat(endDate, g_user_date_format);
    var diff= ed- sd;

    if (diff != 3)
    {
     g_form.addErrorMessage("End date should be 3 days after the start date");
    return false;

    }
}

 

If my answer has helped with your question, please mark it as helpful and correct.

 

Thanks!

Community Alums
Not applicable

Hello @Misbah Sayyed ,

 

You can use UI policy for date validations.

use conditions like this in your ui policy

AnandMahajan_0-1683113299989.png

 

AnandMahajan_1-1683113343284.png

 

 

For more date validation refer this article.

 

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

 

Regards

Anand

Ankur Bawiskar
Tera Patron
Tera Patron

@Misbah Sayyed 

you can use UI policy with no script as per what Anand has shared

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