- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 12:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 10:01 AM
Please check your instance. I have created a new onchnage client script and script include. It is working as expected.
onChange:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ValidateDate');
ga.addParam('sysparm_name','dateValidation');
ga.addParam('sysparm_date',newValue);
ga.getXML(CallBack);
function CallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='true'){
alert("pls select atleast 48hrs or more from now");
g_form.setValue('lpar_refreshed','');
}
}
}
Script include:
var ValidateDate = Class.create();
ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
dateValidation: function(){
return (gs.dateDiff(gs.nowDateTime(),new GlideDateTime(this.getParameter('sysparm_date')), true)/3600<48);
},
type: 'ValidateDate'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 08:16 PM
Ya , I'm new to it . So if u can give me scrip for it .
On Tuesday, September 13, 2016, abhi_r <community-no-reply@servicenow.com>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 08:49 PM
Use this Script
In client script :
var da = new GlideAjax('CustomDateTime');
da.addParam('sysparm_name','getDefaultEndDate');
da.addParam('sysparm_now',newValue);
da.addParam('sysparm_quant','48');
da.getXMLWait();
var end_date = da.getAnswer();
if(g_form.getValue('lPAR name') < end_date)
{
Alert (" LPAR date should be Greater than 2days from Now ");
g_form.setValue('lPAR name','');
}
Script include : ClientDateTimeUtils
Mark Client callable : true
getDefaultEndDate: function() {
var startDate = this.getParameter('sysparm_now');
var addQuantity = this.getParameter('sysparm_quant');
var end_date = new GlideDateTime();
end_date.setDisplayValue(startDate);
end_date.addSeconds(parseInt(addQuantity)*(60*60));
end_date = end_date.getDisplayValue();
return end_date;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 08:51 PM
Replace 24 with 48 .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 09:13 PM
Here is a function that is entirely client-side:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
var fieldName = 'date';
g_form.hideFieldMsg(fieldName, true);
if (!newValue)
return;
function getJSDate(dateStr) {
// Returns a Date object from the Users Date/Time format
var dateTime = dateStr.split(' ');
var date = dateTime[0].split(/[\-\.\/]/);
var time = dateTime[1].split(':');
var day, month, year, hour = time[0], min = time[1], sec = time[2];
if (g_user_date_time_format.match(/^dd/)) {
// little-endian
day = date[0];
month = date[1];
year = date[2];
} else if (g_user_date_time_format.match(/^yyyy/)) {
// big-endian
year = date[0];
month = date[1];
day = date[2];
} else {
// middle-endian
month = date[0];
day = date[1];
year = date[2];
}
return new Date(year, month-1, day, hour, min, sec);
}
var now = new Date();
var newDate = getJSDate(newValue);
var diff = newDate.getTime() - now.getTime();
var twoDays = 172800000; // 2 days in milliseconds
twoDays -= 60000; // Take off a minute to be less strict (better UX)
if (diff < twoDays) {
g_form.showFieldMsg(fieldName, 'Please pick a time at least 48 hours in the future', 'error');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 08:52 AM
Hi Geoffrey .
thank you for your response. In your screen shot i see that you using two date time variables and finding the difference between them .
But in my case i have only one date time variable and need to find from that .
If user selects the date and time which is less than 48hrs , then a dialogue box shuld pop out telling user to select time and date atleast 48hrs from now . and that date time field shule reset and ready for user to select fresh date and time.
let me know if you need any more info for this .
thanks