- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 12:18 PM
What I'm trying to accomplish is that: Start Date cannot be in the past
This is my script:
but my problem is that , I need to be able to select today's date as well, but with this script it doesn't let me .
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date().getTime();
var start = new Date(g_form.getValue('start_date'));
g_form.hideFieldMsg('start_date', true);
if(start<today)
{
g_form.showFieldMsg('start_date','Start date cannot be in the past','error');
g_form.clearValue('start_date');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 09:10 PM
Write a UI policy with the following condition :
Write following script :
function onCondition() {
g_form.setValue('date_of_joining', '');
alert("Enter valid date");
}
This is working fine for me. Try it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 12:35 PM
Try calling "getTime()" on your start variable:
var start = new Date(g_form.getValue('start_date')).getTime();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 01:18 PM
Hi,
I created a Script include to achieve this functionality.
1) Create a Script include with name 'CompareDateTime' and following code
var CompareDateTime = Class.create();
CompareDateTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareDate: function () {
var answer = "false";
var dateOne = this.getParameter('sysparm_date');
var datetwo = gs.nowDateTime();
answer = gs.dateDiff(dateOne,datetwo, true);
if(answer >= 0){
return 'false' ;
}
2) Now create a onchange client script on change of your datetime field. In my below example the datetime field name is 'u_termination_date'
var dt1 = g_form.getValue('u_termination_date');
var glideAJ = new GlideAjax('CompareDateTime');
glideAJ.addParam('sysparm_name' , 'compareDate');
glideAJ.addParam('sysparm_date', dt1);
glideAJ.getXML(callBack);
function callBack(response){
var answer = response.responseXML.documentElement.getAttribute("answer")
if(answer =='false')
{
g_form.showErrorBox('u_termination_date' , 'Termination date time should be greater than current date time');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 04:32 PM
You should be able to use: var start = g_form.getValue('start_date')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 09:10 PM