
- 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-10-2017 03:06 AM
Yes, that what I did in my test instance too, but was looking for a setDisplayValue() way to do it more elegantly.
Anyway, good for you