- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 01:55 PM
I am working on a script include in which I pull an expiration date from the existing table and compare it to the current Date/Time. I have written the following script:
var gdt_expdt = new GlideDateTime();
gdt_expdt.setValue(gr_usr.getValue('expiration_date'));
var gdt_updt = new GlideDateTime();
gdt_updt.compareTo(gdt_expdt);
When I log the result, it shows that gdt_updt is still the current date/time. Something seems to be going wrong in Line 4 where I have tried to use compareTo(). Can anyone see where it is that I am going wrong here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 03:54 PM
your script worked for me. whats the value of gs.log(gdt_expdt), gs.log(gdt_updt) and gs.log(gdt_updt.compareTo(gdt_expdt))? My script
var gr_usr = new GlideRecord('incident');
gr_usr.addQuery("number", 'INC0047595');
gr_usr.query();
gr_usr.next();
gs.log('incident opened: ' + gr_usr.getValue('opened_at'));
var gdt_expdt = new GlideDateTime();
gdt_expdt.setValue(gr_usr.getValue('opened_at'));
gs.log('created: ' + gdt_expdt);
var gdt_updt = new GlideDateTime();
gs.log('current: ' + gdt_updt);
gdt_updt.compareTo(gdt_expdt);
gs.log('compare: ' + gdt_updt.compareTo(gdt_expdt));
I dont think you need to worry about Timezone issue as script include runs on server. both current and expiration value are of server value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 02:25 PM
Try
var gdt_expdt = gr_usr.expiration_date.getGlideObject()
And then see what you get. I'm wondering if you are having a time zone issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 03:54 PM
your script worked for me. whats the value of gs.log(gdt_expdt), gs.log(gdt_updt) and gs.log(gdt_updt.compareTo(gdt_expdt))? My script
var gr_usr = new GlideRecord('incident');
gr_usr.addQuery("number", 'INC0047595');
gr_usr.query();
gr_usr.next();
gs.log('incident opened: ' + gr_usr.getValue('opened_at'));
var gdt_expdt = new GlideDateTime();
gdt_expdt.setValue(gr_usr.getValue('opened_at'));
gs.log('created: ' + gdt_expdt);
var gdt_updt = new GlideDateTime();
gs.log('current: ' + gdt_updt);
gdt_updt.compareTo(gdt_expdt);
gs.log('compare: ' + gdt_updt.compareTo(gdt_expdt));
I dont think you need to worry about Timezone issue as script include runs on server. both current and expiration value are of server value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 05:40 PM
It turns out my error was in how I was trying to log it. Thanks for your help, Ajit!