- 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 10:47 PM
Hi,
It's good if user select date from calander only.
So that all user use same formate. To achive this make your date field read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 10:52 PM
Maybe but choosing date format is for user convenient , so we are not going to make that as read only.
I have tried getdatefromformat(), but it shows as browser console issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 01:38 AM
Hi,
See it
@ https://docs.servicenow.com/bundle/london-application-development/page/script/useful-scripts/concept/c_ValidateDateAndTime.html
it's provided by ServiceNow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 11:08 PM
HI,
Can you show me Script include?
Thanks,
Ashutosh