Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to show Favorites in the Show Me Everything topics of VA in Employee Center

kmolson73
Tera Expert

Currently I am aware that the Favorites for Employee Center now reside in the sp_favorite table. I know there is a widget and the users can get to My Favorites by clicking the link on the homepage in ESC. I have a request in to also add the list of favorites in the show me everything link (topics) within the Virtual Agent. So far I have been unable to get it to work. I tried creating a new topic but my script does not bring up the list of the users favorites. I looked at the OOB topic blocks but they use the bookmarks table which contains URL's etc. where as the sp_favorites table only contains the User, reference document and reference table. Any ideas on how I can query that table to form a list of the favorites they can choose from?  

1 REPLY 1

kmolson73
Tera Expert

So far this is what I have, my topic "My Favorites" has a Dynamic choice where I have the below script. It is showing my favorites when I test it (see attached image) but if I click on a favorite from the choices it doesn't go to the record producer/catalog item or knowledge article. How do I get it to go to the correct record? 

 

(function execute() {
var options = [];

// get variables
var count = 0;
 
// query current favorites
var gr = new GlideRecordSecure('sp_favorite');
gr.addQuery('user', vaInputs.user);
gr.orderByDesc('sys_created_on');
gr.query();

// get total count, used for pagination
count = gr.getRowCount();
vaVars.count = count;

// page of favorites
var cnt = 0;
while(gr.next()) {
var value = gr.getUniqueValue();
var label = gr.getDisplayValue('reference_document');
 

options.push({
'value': value,
'label': label
});

cnt++;
}


return options;

 
})();