- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 06:08 AM
Hi,
What is the easiest way to achieve the following in a Catalog Client Script
1) Get current date time
2) Compare it with Date Input Variable
If Input Variable before today's date, then Show a field message.
Thank you in advance for all your answers.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 06:46 AM
Looks like its expected.
Data validation showFieldMsg not working in Service Portal - Known Error (servicenow.com)
The workaround is to use clearValue before showFieldMsg if you want the message to persist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 06:41 AM
Can you show screenshot of everything
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 06:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 06:46 AM
Looks like its expected.
Data validation showFieldMsg not working in Service Portal - Known Error (servicenow.com)
The workaround is to use clearValue before showFieldMsg if you want the message to persist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 08:00 AM
Hi Anurag,
The requirement has now changed to allow today's date to be selected, but not before current time.
The UI Policy in this case does not work.
Any suggestions on how to achieve this in a Catalog Client Script?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 06:16 AM
Hello @xhensilahad ,
Below is a onSubmit catalog client script:
function onSubmit() {
// Get current date and time
var currentDate = new Date();
// Get the input variable value (replace 'date' with the actual variable name)
var inputDate = g_form.getValue('date');
// Convert input date string to a Date object
var inputDateObj = new Date(inputDate);
// Compare the input date with the current date
if (inputDateObj < currentDate) {
// Show field message if the input date is before today
g_form.addErrorMessage('The selected date cannot be in the past.');
g_form.clearValue('date');
return false; // Prevent form submission
}
return true; // Allow form submission
}
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish