Show a field if Date/Time field is 'more than 12 hours' from nowDateTime?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 07:34 PM
Hi - I am not that great at date/time scripts.
I am looking for a client script to compare a custom date/time field and if the date/time is more than 8 hours ago, I want to display a field.
Can someone help me out/provide guidance?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 01:03 PM
Yea it's just not working.
I created the Script Include just as you've shown, I've created the Client
script as shown with the 'setvisible' lines of code added...no dice.
Essentially all I'm trying to do, is flag when a user says a Change is an
emergency but the original start of the problem was more than 8 hours ago
in the past...then show fields to explain why it's an emergency if it's
been ongoing for more than 8 hours.
With everything in place exactly as provided, based off the change of a
date/time field, I can never get the first alert if 'true' to display
(Selected time is more than 12 hours).
Only get the 'Good to Go' message popup.
Script needs to look at 'Issue Start Date' and compare to current
date/time. If the hours in the past exceed 8, then show 2 fields. Not
sure why this isn't working.
Thanks for looking!
On Sat, Jul 15, 2017 at 3:54 PM, explorenow <

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 01:42 PM
Made little change in Script include, please check if this helps.
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function () {
var opdt = this.getParameter('sysparm_dt');
var seconds = '28800'; //no Seconds in 8 hours
var gdt = new GlideDateTime(opdt);
var nowdt = new GlideDateTime();
var diff = gs.dateDiff(nowdt, gdt, true);
gs.log(diff);
if(parseInt(diff) < parseInt(seconds))
return true;
else
return false;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 01:54 PM
Doesn't work...I get the 'Good to Go' prompt regardless of what date I
pick...3 days past, 3 days future, current day.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var opdt = g_form.getValue('u_issue_start_time'); //Replace the date field
name accordingly
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.addParam('sysparm_dt', opdt);
ajax.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer =
serverResponse.responseXML.documentElement.getAttribute("answer");
if(answer == 'true'){
//g_form.setVisible('u_why_is_issue_urgent', true);
//g_form.setVisible('u_more_escalation_info', true);
alert('Selected time is more than 12 hours');
}
else {
//g_form.setVisible('u_why_is_issue_urgent', false);
//g_form.setVisible('u_more_escalation_info', false);
alert('Good to GO');
}
}
}
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor,
});
On Sat, Jul 15, 2017 at 4:43 PM, explorenow <

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 02:06 PM
Please give me both the code which you are using and I will try to replicate the issue here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 02:29 PM
Can you also please check what logs are you getting in system logs using gs.log(diff); in script include when you select different dates?