The CreatorCon Call for Content is officially open! Get started here.

Error message: Can't find method com.glide.schedules.Schedule.duration(com.glide.glideobject.GlideDateTime,undefined)

Stewe Lundin
Mega Guru

Hi hive mind!

I'm building a filter where I want to filter out changes that are older than 2 workdays (16 hrs) ant that have not yet received a value in the u_estimated _at

I know my problem is the Data type and HOW i treat the date/time values in the cod, but I cant get around it.

The code :

var myEnd = gs.nowDateTime();

var gr = new GlideRecord('change_request');

gr.addEncodedQuery('active=true^u_estimated_atISEMPTY');

gr.query();

gs.print('rowCount:' + gr.getRowCount());

gs.print('Now:' + myEnd);

while(gr.next()){

  gs.print('***' + gr.sys_id);

  var myStart = gr.sys_created_on;

  gs.print(myStart);

  var time = ax_calcWorkdaySchedule(myStart, myEnd);

  gs.print('Calc time:' + time);

}

function ax_calcWorkdaySchedule(start, end) {

// Get the user

var usr = new GlideRecord('sys_user');

usr.get(gs.getUserID());

// Create schedule - pass in the sys_id of your standard work day schedule and pass in the users timezone

var sched = new GlideSchedule('eac2cc49dbd6e60076fabc2ffe9619db',usr.time_zone);

// Get duration based on schedule/timezone

return (sched.duration(start.getGlideObject(), end.getGlideObject()));

}

The error message;
Javascript compiler exception: Can't find method com.glide.schedules.Schedule.duration(com.glide.glideobject.GlideDateTime,undefined). (null.null.script; line 22) in:


The function is normally included in the Script includes but in this case I just copied it in to the code just to show it here(and yes I have change the name of it so I dont have and issue with that).


Regardin myEnd and myStart, I have tried, .toString(), getGlideObject() as well.

The function works when I use it from business rules and use values from current.value, and returns correkt values without error messages...

3 REPLIES 3

dravvyramlochun
ServiceNow Employee
ServiceNow Employee

Thanks but getDisplayValue() dose not apply here.
This is not in a form or in a business rule.



And If I remember correct getDisplayValue() returns a String and would be the same as toString()


and this dose no difference.


var time = ax_calcWorkdaySchedule(myStart.toString(), myEnd.toString());


The SN Nerd
Giga Sage
Giga Sage

Hey Stewe,



gs.nowDateTime returns a string.


https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GS-nowDateTime



getGlideObject() is a function of the GlideElement class (fields)


https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GlideElement-getGlideObject



Alas, you are getting undefined, because strings do not have a function called getGlideObject().



Use this instead at Line 1



var myEnd = new GlideDateTime(); //Gets the current Date and Time

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022