- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2021 09:02 AM
Hi! - I have a date field variable named change_date in a catalog item. I want to send the user an error message if the date they enter is less than the current date plus 3 days - I presume I need to do this in a catalog client script but unsure of the logic to use - Thanks!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 06:48 AM
In the Execute if true script do this
1) clear the variable and make it mandatory
2) This will ensure the user gives valid date before submission
g_form.clearValue('variableName'); // your variable name here
g_form.setMandatory('variableName', true); // your variable name here
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2021 09:31 AM
Hi Mike,
You could certainly use a client script to achieve this. You would need to leverage GlideAjax to pass your date to a script include where you can use the GlideDateTime API to do the validation. See the following for details on those methods:
https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/c_GlideAjaxAPI
https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_APIRef#r_ScopedGlideDateTimeGlideDateTime
For your case however, I think you can go with a simpler technique of using a Catalog UI policy and build your validation condition using the UI policy's condition builder. If the condition evaluates to true, use the script field to throw a form error. Here is a SS of a mock up of that:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2021 09:36 AM
Script to display the error:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 06:42 AM
Thanks Bob!
I added the ui policy and it works fine & sends an error message, but even though the date is 'invalid' (less than today + 3) it still lets me submit the request. How can the submission be 'stopped' if the value entered into the date field is invalid?
Thanks, Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 06:48 AM
In the Execute if true script do this
1) clear the variable and make it mandatory
2) This will ensure the user gives valid date before submission
g_form.clearValue('variableName'); // your variable name here
g_form.setMandatory('variableName', true); // your variable name here
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader