Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideDateTime.before() or .after() not working, please help?

joshuamayes
Giga Expert

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?


					
				
			
			
				
			
			
				
1 ACCEPTED SOLUTION

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.


View solution in original post

5 REPLIES 5

Haha glad you gt it