Hi Team, I have start date , and return date fields in catalog item form  but i need to select "retu

AA6
Tera Contributor

Hi Team, I have start date , and return date fields in catalog item form  but i need to select "return date" is after start date  and return date should not select past date.

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@AA6 

you can use UI policy on return date for validating against start date

then 1 more UI policy on return date for restricting past date

check this

No Code date validations through (Catalog) UI Policies 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @AA6 

 

You can use the Catalog UI policy for this. which is low code. Give a try and share the feedback..

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Juhi Poddar
Kilo Patron

Hello @AA6 

You cannot directly restrict date selection in the calendar, but you can display an error message on the Return Date field to guide users to select a date after the Start Date.

Here is something that you can try:

Create an onChange catalog client script for the Return Date field:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var startDate = g_form.getValue('start_date'); 
    if (startDate) {
        if (newValue < startDate) {
            g_form.showFieldMsg('return_date', 'End date should always be after start date', 'error');
        } else {
            g_form.hideFieldMsg('return_date');
        }
    } else {
        g_form.showFieldMsg('return_date', 'Please fill the start date', 'error');
    }
}

Note:

  • I have assumed the backend field names are start_date and return_date. Please replace them with the actual field names used in your catalog item.
  • This script ensures that:
    • A Start Date must be entered before selecting a Return Date.
    • The Return Date cannot be earlier than the Start Date.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

@AA6 

Additionally, create another onChange script for the Start Date field:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   g_form.clearValue('return_date');
   g_form.hideFieldMsg('return_date');
}

This script ensures that whenever the Start Date is changed, any previously selected Return Date is cleared. This prevents users from setting a Return Date before the Start Date and ensures the correct sequence of date selection.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar