- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 08:22 AM
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:
Any help or thoughts would be appreciated. Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 12:25 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 09:54 AM - edited 01-17-2025 10:49 AM
Hi @snoozer - To populate the slushbucket, it is good practice to use aserver-side GlideRecord query to retrieve the data, then pass the result to the client-side slushbucket using GlideAjax.
If you would prefer not to go that route, something like this should work:
// Called when the UI page loads
addLoadEvent(function () {
//Load the users when the UI page loads
amf_slush.clear();
_getAMFEntriesForSlush();
return false;
});
function _getAMFEntriesForSlush() {
var amfGR = new GlideRecord('u_amf_entry');
amfGR.query(_amfCallBack);
}
function _amfCallBack(amfGR) {
if (!amfGR)
return;
while (amfGR.next()) {
var amfName = amfGR.getValue('u_name');
var amfID = amfGR.getValue('sys_id');
amf_slush.addLeftChoice(amfID, amfName);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 12:11 PM
I may have to try the AJAX, but I really didn't want to bother with it.
What you wrote is exactly what I have and it's what's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 12:31 PM
Sounds like gremlins 😀
Glad it's working. I was coming back to update...I did pop that code sample into a UI page (updated to work with 'sys_user'), works as expected:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 07:56 AM
Haha. I never seem to account for gremlins.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 12:26 PM
I ended up copying my code to a brand new UI page and it works with no changes. Just so weird.