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-16-2017 10:03 PM
I don't think so we have to use hoursAgo since our requirement is to check next 8 hours.
Can you please put alert in client script to check if it's capturing the date
var opdt = g_form.getValue('u_issue_start_time');
alert('Issue_start_time:' + opdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 12:11 PM
Hi Shishir
Additional Information:
This is for a record producer, so it will be a catalog client script.
I created the Script Include and named it 'MyDateTimeAjax'.
When the record producer first loads, there are several fields that are hidden by a catalog UI policy.
If Change type picked = Emergency, then I have several fields displaying, including 'Issue Start Time'.
I need the script to look at start time and if it's > 12 hours, display 2 fields.
In testing out what you've provided, the 'Issue Start Date' is empty to begin with, so the 2 fields u_why_is_issue_urgent and u_more_escalation_info, are displayed as soon as I pick Type=Emergency. The fields need to remain hidden until a value is populated in 'Issue Start Time'.
I did enter a date within 12 hours and the fields disappeared, but when I changed the date to outside 12 hours, the fields did not appear.
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);
}
else {
g_form.setVisible('u_why_is_issue_urgent', false);
g_form.setVisible('u_more_escalation_info', false);
}
}
}