- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 10:02 AM
Hello all,
We have a couple of catalog items that use the date variable type and we want to restrict the user's from selecting a date in the past. Is this possible?
Also, we have Start Date and End Date on one our catalog items, does anyone know if its possible to restrict the end date to show dates past the selected start date?
Any suggestions are greatly appreciated!
Thanks,
Grace
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 11:12 AM
Hi,
Kindly use this code:
Suppose the variable/field name is 'current_date' on the catalog item/form
---'OnChange' Client Script
--field name : current_date
-Script :
function onChange(control, oldValue, newValue, isLoading)
{
if(isLoading)
{
return;
}
//start the validation
if(newValue != '')
{
var ga = new GlideAjax('ConfirmDate');
ga.addParam('sysparm_name', 'chkCurrDate');
ga.addParam('sysparm_date',g_form.getValue('current_date'));
ga.getXML(NewParse);
}
function NewParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
alert("Date selected is a past entry.");
g_form.setValue('current_date', ''); // Setting the variable as empty
}}}
----Script include :-
---Name : ConfirmDate
--Client callable : true
-Script :
var ConfirmDate= Class.create();
ConfirmDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCurrDate : function() {
var start = this.getParameter('sysparm_date');
var currDay = gs.now();
if(start < currDay){
return false;
}
else
{ return true; } } });
regards,
Munender
**Kindly hit correct/helpful if found useful

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2018 04:50 PM
Hi Munender, This is a bit of a silly question, sorry I'm confused- Which Script Include should I be creating for your solution above?
I cannot see script includes on my catalog item, but I can find the menu item System UI > Script Includes?
If it is this Script Includes under System UI what is it that ties it back to that catalog item\variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2018 11:31 PM
Hi,
You will find it under system definition>script include
Regards,
Munender

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2018 09:23 PM
Thanks Munender! That worked, you are a legend!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2018 02:24 AM
Hi there, I am using your script and works well until I want to select a date for the following month. It appears that the script is only looking at the day rather than the month/year.
Could you help me in changing the script include so that it looks at the actual date rather than just the day?
Any help would be appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 09:35 AM
Hi Matt,
I had to change mine to because our users were trying to select dates in 2019 and they were getting a "past date error" because only the month and day were being looked at.
Look at this thread: https://community.servicenow.com/community?id=community_question&sys_id=abd88f61db5cdbc01dcaf3231f96... I found my solution here hope this helps!
Grace