- 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
‎03-20-2018 03:08 PM
Thank you Munender this is exactly what I was looking for! Before I mark as correct just out curiosity would you know if there is a way to restrict the end date to only have selectable dates that are after the start date?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2018 05:03 AM
Hi,
A good question but the thing is that the glide date-time picker is OOB and if you want to achieve your desired output ,then you have create your own gadget and a UI Macro to define your date-time gadget, then a formatter to make your UI Macro available on your form.
So,I would advise not to proceed with that becuase alerts would serve your purpose easily as I described in earlier reply.
Regards,
Munender
**Kindly hit correct/helpful if found useful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2018 09:18 AM
Got it! Thank you Munender for you all your help and input, will definitely keep that in mind if ever asked for that requirement!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 01:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 01:36 AM
Are you sure the Javascript on the server side is such a happy place to be able to compare string < string and to make a correct date comparison?
The function getParameter returns a string.
gs.now() also returns a string.
var start = this.getParameter('sysparm_date');
var currDay = gs.now();
if(start < currDay){
If you want to go this way you have to parse the strings into GlideDateTime objects and then compare with for example onOrBefore(...) or directly compare the milliseconds through getNumericValue()