
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 08:08 AM
Hi all,
I know various flavors of this question have been asked before; yet I can't seem to find a simple solution.
I am running Geneva.
On the CHG form, I have 2 date/time fields:
- Start Date (start_date)
- Notification Date (u_notification_date)
If the user selects 5/8/17 as the start date, I'd like the Notification date to automatically default to the date before @ 14:30:00. In this example, the Notification Date would default to 5/7/17 @ 14:30:00
Any help is greatly appreciated
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 09:53 AM
Hi Matthew,
If both are date/time, this is what works for me:
onChange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.clearValue('u_notification_date');
var start = g_form.getValue('start_date');
//var ga = new GlideAjax('')
var ga = new GlideAjax('setMyDate');
ga.addParam('sysparm_name','getDateTime');
ga.addParam('sysparm_start',start);
ga.getXML(ParseTheTime);
function ParseTheTime(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_notification_date',answer);
}
}
script include:
var setMyDate = Class.create();
setMyDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDateTime : function() {
var start = this.getParameter('sysparm_start');
var days = 1;
var strDate = start.split(' ')[0];
var vDate = new GlideDateTime(strDate);
vDate.addDays(-days);
var vDateStr = vDate.getDate() + ' 14:30:00';
return vDateStr;
},
type: 'setMyDate'
});
Based on amlanpal 's script in another post.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 09:17 AM
Hi Matthew,
To achieve this requirement you need to write one onChange Client Script on Change request (change_request) table. In the Client Script you need to call the Script include where the calculation will be done. Please find the Client Script and Script Include below. It is working properly in my instance. Request you to give it a try and let me know.
Client Script:
Script Include:
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 10:31 AM
Amlan-
This works but I was getting some weird results when I spit the results out in the log file. The date/time would be flipped and it wouldn't subtract 1 day. Not sure why. But this is a good start. Going to play w/ this some more
Matthew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 09:53 AM
Hi Matthew,
If both are date/time, this is what works for me:
onChange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.clearValue('u_notification_date');
var start = g_form.getValue('start_date');
//var ga = new GlideAjax('')
var ga = new GlideAjax('setMyDate');
ga.addParam('sysparm_name','getDateTime');
ga.addParam('sysparm_start',start);
ga.getXML(ParseTheTime);
function ParseTheTime(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_notification_date',answer);
}
}
script include:
var setMyDate = Class.create();
setMyDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDateTime : function() {
var start = this.getParameter('sysparm_start');
var days = 1;
var strDate = start.split(' ')[0];
var vDate = new GlideDateTime(strDate);
vDate.addDays(-days);
var vDateStr = vDate.getDate() + ' 14:30:00';
return vDateStr;
},
type: 'setMyDate'
});
Based on amlanpal 's script in another post.
harel

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 10:36 AM