Restrict Date Entry on a Variable in a Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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;
}
Kind Regards,
Azar
Serivenow Rising Star ⭐
Architect@ KPMG.