- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2017 09:37 AM
I need an 'OnChange' script that will check to see whether the entered 'start_date' that is less than 2 weeks from today (or whatever day they are filling out the form). If they enter a date less than 2 weeks away, I want to display a pop up message and prevent them from submitting the form.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 05:22 AM
Hi Nicole,
If you don't want to do ajax calls each time, you can use JavaScript validation in onChange client script and onSubmit script :
var date1 = new Date(g_form.getValue('start_date');
var date2 = new Date();
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if(diffDays >= 14) {
alert("Error Message");
return false;
}
else
return true;
Regards,
Chirag Bagdai

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 11:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 11:57 AM
try this one,
testing: function(){
var abc = new GlideDateTime();
abc.setValue(startDT);
abc.daysAgo(-14);
if (startDT>abc){
return false;
else{
return true;
}
},
gsetNowDateTime: function(){
return gs.nowDatetime();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 04:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 05:03 AM
Was able to get rid of most errors:
var AbstractAjaxProcessorDate = Class.create();
AbstractAjaxProcessorDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'AbstractAjaxProcessorDate'
}
testing: function(){
var abc = new GlideDateTime();
abc.setValue(startDT);
abc.daysAgo(-14);
if (startDT>abc){
return false;
else{
return true;
}
},
gsetNowDateTime: function(){
return gs.nowDatetime();
},
Except for this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 05:04 AM
you need to remove line4 and as well as return in else causing the errors.
Try this one,
var AbstractAjaxProcessorDate = Class.create();
AbstractAjaxProcessorDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
testing: function(){
var ans = true;
var abc = new GlideDateTime();
abc.setValue(startDT);
abc.daysAgo(-14);
if (startDT>abc){
ans =false;
}
return ans;
},
gsetNowDateTime: function(){
return gs.nowDatetime();
},
type: 'AbstractAjaxProcessorDate'
});