
- 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 11:27 AM
Just noticed one small issue. As you can see, our date format is: MM-dd-yyyy but the script will generate it like: yyyy-MM-dd.
Because we like to be different, the date selector still shows the 8th, but the data inserted into the field as text is the 16th.
If i update the script include, can i format the output of the date to our format: MM-dd-yyyy?
I see a property called 'setDisplayValue(String value, String format)' but am not sure how it incorporate this into the script include.
thanks Harel!
Matthew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 08:38 AM
Hi Matthew,
I don't think that the script include - mine or amlanpal 's - take the date format into account, though.
Just curious how come some of your fields are in yyy-MM-dd format and others are in MM-dd-yyyy ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 09:02 AM
Thanks for mentioning me oharel. I'm also curious to know how this is been configured? It will be really interesting to know how some fields are configured as MM-DD-YYYY and some are in YYYY-MM-DD.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 10:06 AM
Hey Harel,
I changed the property glide.sys.date_format to MM-dd-yyyy
That is a screen shot from an old ticket when the dates were yyyy-MM-dd
If i create a new ticket, the dates are MM-dd-yyyy, but old tickets that have date values are yyyy-MM-dd.
I'm playing w/ the formatting of the date now to see if I can get the correct date selected on the calendar. I'll keep you all posted
matthew

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 10:41 AM
Harel/Amlan-
It aint' pretty but it works:
var setMyDate = Class.create();
setMyDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDateTime : function() {
var start = this.getParameter('sysparm_start');
gs.log("original date: " + start);
var days = 1;
var strDate = start.split(' ')[0];
var strMnth = start.split('-')[0];
var strDay = start.split('-')[1];
var strYr = start.split('-')[2];
var year = strYr.substring(0, 4);
//gs.log("new start date: " + strDate);
gs.log("year: " + year);
gs.log("month: " + strMnth);
gs.log("day: " + strDay);
var newDate = strDay -1;
gs.log("new day: " + newDate);
// var vDate = new GlideDateTime(strDate);
// gs.log("New start date 2: " + vDate);
// vDate.addDays(-days);
// var vDateStr = vDate.getDate() + ' 14:30:00';
var vDateStr = strMnth + "-" + newDate + "-" + year + ' 14:30:00';
return vDateStr;
},
type: 'setMyDate'
});
I basically had to take the date that was selected, then split it up into 3 chunks:
Year
Month
Day
The put it in the order that I wanted and add 14:30 to the end
Now the other days on my old ticket are MM-dd-yyyy for some reason. I can't explain that one