Client side GlideRecord callback not working

snoozer
Mega Guru

I'm working on a UI page. I need to load some values from a table into a slushbucket for users to choose. The problem is that in the callback function, I can not access the GlideRecord object. Here is my code:

 

function _getAMFEntriesForSlush()
{
    var amfGR = new GlideRecord('u_amf_entry');
    amfGR.query(_amfCallBack);
}

function _amfCallBack(amfGR)
{
     alert("hi" + amfGR);                                      //  I get this alert
     alert("hi " + amfGR.getRowCount());           // I do not get this alert

// none of the following happens
    while (amfGR.next())
	{
        var amfName = amfGR.getValue('u_name');
        var amfID = amfGR.getValue('sys_id');
        amf_slush.addLeftChoice(amfID, amfName);
    }
}

The code to populate the slushbucket never gets run. I put in some alerts to see where the code is failing. I get that first alert, and it says "hi [object Object]". I do not get the second alert, which tells me there's a problem with referencing the GlideRecord object. Why?

 

What's really frustrating is that I have done this exact thing before and it works perfectly. I copied that code to write this. The other code works, but this doesn't.

 

Here's a the reference I used about client side GlideRecords:

https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/app-store/dev_portal/API_reference/...

 

Any help or thoughts would be appreciated. Thanks.

1 ACCEPTED SOLUTION

snoozer
Mega Guru

I ended up creating a whole new UI Page and copying the code into the new page. It works with no changes. No idea why the previous page didn't work.

View solution in original post

10 REPLIES 10

Juhi Poddar
Kilo Patron

Hello @snoozer 

Found this from the document you have referred:

JuhiPoddar_0-1737132818972.png

Try modifying the script as shown in the highlighted part.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

The row count is not what I'm looking for here. That's just something I tried to output to se where the code is breaking down.

 

What I want is for the lines following the "// none of the following happen" comment to run. They do not get run at the moment.

Chaitanya ILCR
Kilo Patron

Hi @snoozer ,
getRowCount() Method Doesn't exist in Client side GlideRecord Class.
that code could be throwing an error at the getRowCount() method.
just comment that line and test the code.
if you want to see the row count you can use GlideAjax or use a temporary count variable and increment it inside the while loop.


 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

I don't really care about the rowCount. I just put that in there to see if accessing something from the GlideRecord was throwing the error. The code still doesn't work when the line is commented out.