Restrict Date Entry on a Variable in a Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @terrieb , You validation is failing because 'Start Date' variable becomes mandatory only when a user changes the value of field manually.
If I understand the requirement correctly, you would like to make the 'Start Date' variable mandatory while also ensuring that the selected date is not in the past. If so, you can achieve this using the following couple of options:
1. Define 'Start Date' variable itself mandatory while creating it and In existing policy, change/create the UI Policy Action as per below screenshot (Ensure you don't make it mandatory again):
OR
2. If you don't want to define 'Start Date' variable as mandatory while creating, then create additional UI policy along with the existing one created by you. In existing policy, change/create the UI Policy Action as per below screenshot:
Below is the description of the new policy
- Policy Order should be greater than existing one and 'On load' checkbox is selected
- Condition 'Start Date' is empty
- UI policy action: select Mandatory as Yes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
This action still did not make the field mandatory when the catalog item was opened.
Instead the solution we found to work, is on the variable in the item we added a default date value of 1/1/1900 which is "against" the policy action to not input a date at or before today's date.
Now, when the catalog item is opened, that field is marked Mandatory and the error message appears. The requestor can no longer bypass the field and has to put in a date not equal to the current date or any date prior to current date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @terrieb , which option did you follow - 1 or 2? Could you please share the complete screenshots of your UI policies or any other changes you made?
Regards,
Nishant