URGENT Help- Function getGlideObject is not allowed in scope Error

ST9
Tera Contributor

Hi All,

I'm creating a notification Menu Item same as in csm portal, but i'm getting error that Function getGlideObject is not allowed in scope x_case.

Please help to correct my code-
---------------------------------------------------------------------------------------------------

var t = data; // shortcut
t.record_watchers = [];
var u = gs.getUser().getID();
var t = data;
t.items = [];
t.count = 0;

t.record_watchers.push({'table':'x_case','filter':'stateIN400^contact=' + u});
var z = new GlideRecord("x_case");
z.addQuery("contact", u);
z.addQuery("state", 'IN', '400');
z.orderByDesc('sys_updated_on');
//z.setLimit(1);
z.query();
while (z.next()) {
var a = {};
$sp.getRecordValues(a, z, 'sys_id,sys_updated_on');
a.number = z.getDisplayValue();
a.__table = z.getRecordClassName();
a.__page = 'x_cases';
a.type = 'record';
a.sortOrder = z.sys_updated_on.getGlideObject.getNumericValue();---> ERROR
t.items.push(a);
t.count++;
}
t.items.sort(function(a, b) {
return b.sortOrder - a.sortOrder;
});

var link = {};
link.title = gs.getMessage('View all notifications');
link.type = 'link';
link.href = '?id=x_notification';
link.items = [];
t.items.unshift(link);

------------------------------------------------------------------------------------------------------------------

1 ACCEPTED SOLUTION

Hi,

please use this

Use GlideDateTime and then use getNumericValue()

a.sortOrder = new GlideDateTime(z.sys_updated_on).getNumericValue();

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Sai Kumar B
Mega Sage
Mega Sage

Hi,

getGlideObject is not supported in the scoped applications instead use the below code to get the numeric value of sys_updated_on

var updatedOn = new GlideDateTime(z.sys_updated_on);
a.sortOrder = updatedOn.getNumericValue();

//If you want the numeric value in seconds 
var durationInSeconds = updatedOn.getNumericValue()/1000;

 

ST9
Tera Contributor

Hi Sai,

Now I'm getting this error - Server JavaScript error "updateOn" is not defined. and error on a.sortOrder = updateOn.getNumericValue();

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

use this

a.sortOrder = z.sys_updated_on.getNumericValue();

Regards
Ankur

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

Hi Ankur,

getting this error on Portal-

Server JavaScript error Cannot find function getNumericValue in object 2022-03-25 08:23:20.

a.sortOrder = z.sys_updated_on.getNumericValue();   - Error