Adding additional record to a GlideRecord object

jbyates
Kilo Explorer

I'm attempting to query the category->catalog items join table to get a set of request items that i can then pass to a list and display on a page. All I need is the request items. I'm trying to query the sc_cat_item_category table to get my list and then construct a GlideRecord on the sc_cat_item table from those records. The problem is I am unable to find a method to add items to a GlideRecord. I have tried "push" but this does not seem to add any records. Is there a built in way to handle this process?

Here is an example of what I have tried:




//query the catalog item and category join table
var categoryItems = new GlideRecord('sc_cat_item_category');
categoryItems.addQuery('sc_category', categoryID);
categoryItems.addActiveQuery();
categoryItems.orderBy('order');
categoryItems.query();
//build a gliderecord consisting of the found catalog items
var catalogItems = new GlideRecord('sc_cat_item');
while(categoryItems.next()){
catalogItems.push(categoryItems.sc_cat_item);
}

return catalogItems;
}

5 REPLIES 5

jbyates
Kilo Explorer

Thank you! Your comment about join caused me to remember the Join query functionality and now it is working. Here is how I got it working:



var documentKey = RP.getParameterValue('sysparm_document_key');
documentKey = documentKey.split(',');

var documentTableName = documentKey[0]
var categoryID = documentKey[1];

var catalogItems = new GlideRecord('sc_cat_item');
var categoryItems = catalogItems.addJoinQuery('sc_cat_item_category');
categoryItems.addCondition('sc_category', categoryID);
catalogItems.orderBy('order');
catalogItems.query();

return catalogItems;