- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 10:41 PM
Hello team,
I have a requirement in change request if user selects the past planned date it should have to popup an alert message to choose the current or future date.
It is working fine for almost all users with my old script,
it fails when user choose the date format like mm/dd/yy in their profile
my new script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var startDateStr = g_form.getValue('start_date');
if(moment) {
var dateFormat = g_user_date_time_format;
var currentDate = new moment(g_form.getValue('start_date'),dateFormat);
alert('currentDate**' + currentDate + 'startDateStr**' +startDateStr);
if(startDateStr <= currentDate) {
alert('"Planned Start Date" must be set to a current or future time');
g_form.setValue('start_date', '');
}
}
}
Old script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var currentTime = '';
var time = new GlideAjax('DateTime');
time.addParam('sysparm_name', 'getNowDateTime');
time.getXML(
function () {
currentTime = time.getAnswer();
if (newValue <= currentTime){
alert('"Planned Start Date" must be set to a current or future time');
g_form.setValue('start_date','');
}
}
);
}
my issue is my new script not able to identify the current date , it shows like below,
How to achieve this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:49 PM
Hi,
pass both newvalue and current value to script include and go comparison there and just return true or false to client script.
Convert both to GlideDateTime and then compare.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:20 PM
The below is my script include:
var DateTime = Class.create();
DateTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNowDateTime: function () {
return gs.nowDateTime();
},
getNowRelativeDateTime: function () {
var relativeDateTime = GlideDateTime(gs.nowDateTime());
relativeDateTime.addSeconds(300);
return relativeDateTime;
},
getNowRelativeFutureDateTime: function () {
var relativeDateTime = GlideDateTime(gs.nowDateTime());
relativeDateTime.addSeconds(-300);
return relativeDateTime;
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:24 PM
Hi,
Correct this line:
var relativeDateTime = GlideDateTime(gs.nowDateTime());
TO
var relativeDateTime = new GlideDateTime(gs.nowDateTime());
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:40 PM
Hi ,
I have updated as like you mentioned,
script include;
var DateTime = Class.create();
DateTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNowDateTime: function () {
return gs.nowDateTime();
},
getNowRelativeDateTime: function () {
var relativeDateTime = new GlideDateTime(gs.nowDateTime());
relativeDateTime.addSeconds(300);
return relativeDateTime;
},
getNowRelativeFutureDateTime: function () {
var relativeDateTime = new GlideDateTime(gs.nowDateTime());
relativeDateTime.addSeconds(-300);
return relativeDateTime;
}
});
Client script;
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var currentTime = '';
var time = new GlideAjax('DateTime');
time.addParam('sysparm_name', 'getNowDateTime');
time.getXML(
function () {
currentTime = time.getAnswer();
alert('newValue**' + newValue + 'currentTime**'+currentTime );
if (newValue <= currentTime){
alert('"Planned Start Date" must be set to a current or future time');
g_form.setValue('start_date','');
}
}
);
}
Please find the below screen shot;
Clearly the new value is greater than the current time but still it satisfy the if condition and showing alert like below
Already I have choosed the future date, this is the issue I am exactly facing

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:49 PM
Hi,
pass both newvalue and current value to script include and go comparison there and just return true or false to client script.
Convert both to GlideDateTime and then compare.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:52 PM
How to do that, will you please share the script?