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.

why my glide DateTime not working

Ravi Borade
Giga Contributor

want to get total number of days from today to date incident 'created'

var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '4728cc7587f81110872b40cf8bbb3543');
incidentGR.query();

if (incidentGR.next()) {
    var today = new GlideDate();
    var endDate = incidentGR.sys_created_on.getDisplayValue().split(' ')[0];
    var diff = GlideDate.subtract(today, endDate);
    var days = diff.getRoundedDayPart();
    gs.info(day);

}

ERROR im getting

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '4728cc7587f81110872b40cf8bbb3543');
incidentGR.query();
if (incidentGR.next()) {
	var today = new GlideDateTime();
	var endDate = new GlideDateTime(incidentGR.sys_created_on);
	var diff = GlideDateTime.subtract(today, endDate);
	var days = diff.getRoundedDayPart();
	gs.info(day);
}

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

thnx Ankur it worked i thought glideDate() only will do the job but i've to learn about getRoundedDayPart()