- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 02:01 PM
Short Version:
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=c_APIRef.dita gives the following example for using GlideDateTime.before()
var gdt1 = new GlideDateTime("2016-05-09 10:11:12");
var gdt2 = new GlideDateTime("2017-06-12 15:11:12");
gs.info(gdt1.before(gdt2));
However when putting it into a background script it outputs "undefined". Why?
Long Version:
I am trying to build a transform script that treats records differently depending on if a field has a date (stored as string) before 2015-01-01. My idea was to just use GlideDateTime.before() to check if the log_date was before the cutoff date. For example:
case 'OPEN' : //This status + assigned to qrsinv is default method for creating a new asset. Anything with this status before Cutoff date 01/01/2015 - Mark as lost
var splitDate = source.u_log_date.split("/");
var strDate = splitDate[2]+'-'+splitDate[0]+'-'+splitDate[1] + ' 00:00:00';
var gd = new GlideDateTime(strDate);
var cutoff = new GlideDateTime('2015-01-01 00:00:00');
if(gd.before(cutoff)){ //Do my code
}else{// more code
}
break;
I'm starting to think that this isn't viable. Any ideas?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 03:23 PM
Yeah I just ran it in Helsinki and I am getting undefined too. The developer doc you are referring to is Istanbul. Here is for Helsinki:
https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=c_APIRef.dita
And before is not defined here, compareTo as mentioned in this Helsinki doc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 03:04 PM
I ran this script in my OOB instance :
var gdt1 = new GlideDateTime("2016-05-09 10:11:12");
var gdt2 = new GlideDateTime("2017-06-12 15:11:12");
gs.info(gdt1.before(gdt2));
It gave me correct output: *** Script: true
Not sure why not working for you, on which version you are on?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 03:15 PM
Interesting...
I'm on Helsinki. Sorry I didn't think to include that in my post.
Also worth noting that I was testing that snippet in background scripts. Did you run it in some other module?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 03:23 PM
Yeah I just ran it in Helsinki and I am getting undefined too. The developer doc you are referring to is Istanbul. Here is for Helsinki:
https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=c_APIRef.dita
And before is not defined here, compareTo as mentioned in this Helsinki doc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 03:27 PM
Thank you so much!! I was going bald trying to figure this out.