Catalog Client Script

CesarV_
Tera Contributor

Hi all,

 

I am trying to configure a Date variable on a Catalog Item form so users can only select a date that is at least two weeks out from the current date. Using a Catalog Client Script, I tried scripting this function, which gives me no errors but seems to not change anything on the form. 

 

Can anyone take a look at my script and tell me what I might be doing wrong? 

 

Example: highlighted dates should be grayed out and not selectable:

CesarV__0-1758897188360.png

 

My Script: 

 

function onLoad() {
    var today = new Date();
    var minDate = new Date();
    minDate.setDate(today.getDate() + 14);

    // Format minDate as yyyy-MM-dd
    var yyyy = minDate.getFullYear();
    var mm = String(minDate.getMonth() + 1).padStart(2, '0');
    var dd = String(minDate.getDate()).padStart(2, '0');
    var formattedMinDate = yyyy + '-' + mm + '-' + dd;

    // Set the min attribute on the date input field
    var dateField = g_form.getControl('requested_fulfillment_date');
    if (dateField) {
        dateField.setAttribute('min', formattedMinDate);
    }
}

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@CesarV_ 

no scripting required and when you use UI policy you need not worry on the date format as well.

UI policy will handle that for you.

check response from @RaghavSh for that UI policy condition

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