- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 11:21 PM - edited 08-03-2023 11:23 PM
validateDatetoDisable.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function() {
var disableDate = this.getParameter('sysparm_disable_dt');
gs.log('Rishi Disable Dt ' + disableDate);
var cDate = new GlideDate();
gs.log('Rishi Current Dt ' + cDate);
//return gs.dateDiff(gs.nowDateTime(), disableDate, true) / 86400;
//return gs.dateDiff(cDate, disableDate, true) / 86400;
return gs.dateDiff(cDate, disableDate, true);
},
type: 'validateDatetoDisable'
});
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var disDate = new GlideAjax('validateDatetoDisable');
disDate.addParam('sysparm_name', 'nowDateTime');
disDate.addParam('sysparm_disable_dt', g_form.getValue('date_to_disable_account'));
disDate.getXML(compareDisableDate);
function compareDisableDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//if (answer <= 0) {To neither allow current date nor past date
if (answer < 0) { //To allow current date but not past date
g_form.addErrorMessage("Date to Disable should not be the Past Date");
g_form.clearValue('date_to_disable_account');
}
}
}
I know this can be achieved through UI Policy Script, but I want this fulfilled through Client Callable Script Include for learning purposes.
Thank You in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 02:56 AM
Oh, sorry, I completely missed the error from the log that you posted.
That error indicates something else, maybe a scope identifier will help?
Here's how I would do it, if going for the client-script/script include way.
Script include:
Client script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 10:22 AM
Okay, that will make it a bit more complicated.
Add these lines to the script to allow for the same day also.
And on another note, make it a habit to use gs.info() instead of gs.log(), since gs.log() does not work in scoped applications.
isBeforeToday: function() {
var compareDate = this.getParameter('sysparm_date_compare');
if (!compareDate)
return 0;
var gdt = new GlideDateTime();
var compareGDT = new GlideDateTime(compareDate);
var systemDay = gdt.getDate().toString();
var compareDay = compareGDT.getDate().toString();
if (systemDay == compareDay) {
return 1;
else {
if (compareGDT.before(gdt)) {
return 0;
} else {
return 1;
}
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 01:48 PM
Thank You @OlaN Sir it is working great, Well Noted 🙂 I will make a habit to use gs.info() instead gs.log() due to the mentioned reason. Both answers are marked as a solution and helpful.
Just a small add, since provided script include not save due to javascript parse/syntax error, so I just added closing '}' after 'if' at line 10/11 in the provided script include (as shown below)
if (systemDay == compareDay) {
return 1;
}
Further for future reference, the final scripts for Date Validation (The date should NOT be the past date, only today's date or any future date is acceptable) are:
-Script Include (Client Callable):
var DisdtValidation = Class.create();
DisdtValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isBeforeToday: function() {
var compareDate = this.getParameter('sysparm_date_compare');
if (!compareDate)
return 0;
var gdt = new GlideDateTime();
var compareGDT = new GlideDateTime(compareDate);
var systemDay = gdt.getDate().toString();
var compareDay = compareGDT.getDate().toString();
if (systemDay == compareDay) {
return 1;
} else {
if (compareGDT.before(gdt)) {
return 0;
} else {
return 1;
}
}
},
type: 'DisdtValidation'
});
-Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.DisdtValidation');
ga.addParam('sysparm_name', 'isBeforeToday');
ga.addParam('sysparm_date_compare', newValue);
ga.getXMLAnswer(validateDisDt);
function validateDisDt(response) {
if (response == 0 || response == '0') {
g_form.clearValue('date_to_disable_account');
g_form.showFieldMsg('date_to_disable_account', 'Invalid Date', 'error');
//g_form.addInfoMessage('Invalid Date');
}
if (response == 1 || response == '1') {
//g_form.addInfoMessage('Valid Date');
g_form.showFieldMsg('date_to_disable_account', 'Valid Date', 'info');
}
}
}
Thank you Once again!