Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Restrict Date Entry on a Variable in a Catalog Item

terrieb
Tera Guru

We have a catalog item that has the variable type of date and the question is Start Date.  

 

We are trying to prevent anyone from inputting today's date as the start date.

 

We have tried the following to prevent this:

 

UI Policy where date can't be at or before today

On the ui Action on the dictionary override record, deselected the mandatory override

Both the UI action and the Variable is set to Mandatory

 

While it works, it only works if someone clicks on that field.  The mandatory symbol does not show up unless they do so and if they try to put in today's date, it won't allow them to submit the request

 

However, if they skip that field, the mandatory symbol does not show up and they can submit the request with that field blank

 

This is critical information so if anyone else has a way to resolve this, we would greatly appreciate it.

 

Thanks!

1 REPLY 1

Its_Azar
Mega Sage

Hi there @terrieb 

 

I wouldn't rely on a UI Policy to make the variable mandatory in this case. Set the catalog variable itself to Mandatory = true so the form always enforces it. Then use an onSubmit Catalog Client Script to validate that the selected date is greater than today. Finally, add server-side validation in your fulfillment logic or Business Rule, since client-side checks can be bypassed.

 

sample script

function onSubmit() {
    var startDate = g_form.getValue('start_date'); // Replace with your variable name

    if (!startDate)
        return false; // Mandatory field will also prevent submission

    var today = new Date();
    today.setHours(0, 0, 0, 0);

    var selected = new Date(startDate);
    selected.setHours(0, 0, 0, 0);

    if (selected <= today) {
        g_form.showFieldMsg(
            'start_date',
            'Start Date must be after today.',
            'error'
        );
        return false;
    }

    return true;
}
☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Architect@ KPMG.