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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 01:43 AM
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 01:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 01:57 AM
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());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 02:24 AM
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