featured content Knowledge article sort order in service portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 03:17 AM
Hi,
I Need to sort the order of featured content Knowledge article based on sys_updated_on in serviceportal. I am using the OOB Widget. Can anyone let me know where I need to modify the serviceportal script
(function() {
options.title = options.title || gs.getMessage('Featured');
options.display_field = options.display_field || "short_description";
options.secondary_fields = options.secondary_fields ? options.secondary_fields.split(",") : getKnowledgeFieldsfromProperties();
options.show_secondary_fields_label = options.show_secondary_fields_label ? options.show_secondary_fields_label == 'true' : false;
options.max_records = options.max_records || gs.getProperty('glide.knowman.content_block_limit')|| '5';
options.always_show = options.always_show ? options.always_show == 'true' : true;
options.knowledge_base = options.knowledge_base || "";
options.reverse = false;
if(options.display_field != "short_description"){
options.secondary_fields.push(options.display_field);
}
var kbService = new KBPortalService();
var j = 0;
var result = [];
var kb = kbService.getFeaturedArticles(options.max_records,options.secondary_fields);
if(kb.results){
kb.results.forEach(function(f){
var record = {};
record.id = f.id+"";
record.link = f.link;
record.direct = f.meta.direct || false;
record.external = f.meta.external || false;
record.external_link = f.meta.external_link;
if (options.display_field){
if(options.display_field == "short_description"){
record.display_field = f.title;
}else{
record.display_field = f.meta[options.display_field].display_value;
}
}
record.order = j;
j++;
record.secondary_fields = [];
options.secondary_fields.forEach(function(key){
if(options.display_field != key)
record.secondary_fields.push(f.meta[key]);
});
result.push(record);
});
}
options.result = result;
data.template = $sp.getWidget("kb-list-widget-template", options);
function getKnowledgeFieldsfromProperties(){
//Generate secondary fields based on legacy properties
var fields = [];
if(gs.getProperty('glide.knowman.search.show_article_number') && gs.getProperty('glide.knowman.search.show_article_number') == 'true'){
var kbMod = new global.KBViewModel();
if(kbMod.isVersioningEnabled()){
fields.push('display_number');
}else{
fields.push('number');
}
}
if(gs.getProperty('glide.knowman.search.show_author') && gs.getProperty('glide.knowman.search.show_author') == 'true')
fields.push('author');
if(gs.getProperty('glide.knowman.search.show_view_count') && gs.getProperty('glide.knowman.search.show_view_count') == 'true')
fields.push('sys_view_count');
if(gs.getProperty('glide.knowman.search.show_last_modified') && gs.getProperty('glide.knowman.search.show_last_modified') == 'true')
fields.push('sys_updated_on');
if(gs.getProperty('glide.knowman.search.show_published') && gs.getProperty('glide.knowman.search.show_published') == 'true')
fields.push('published');
if(gs.getProperty('glide.knowman.show_unpublished') && gs.getProperty('glide.knowman.show_unpublished') == 'true'){
fields.push('workflow_state');
}
fields.push('rating');
return fields;
}
})();
Thanks
Sai Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 09:28 AM
Hello Sai Krishna,
did you get the solutiuon for same?i have the same requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 10:04 PM
Hi Varsha,
We didn't got the solution for this issue. We need to modify the widget script to sort this issue but we are unable to findout that.
Regards
Sai Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 07:11 AM
Thank you Sai Krishna for the update,
Hello Community Experts,
Can you please assist me on the same?
Thanks
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 02:50 AM
I've managed to get this working after cloning the 2 widgets and updating the code as follows
Knowledge Featured Articles
Instead of ordering by an integer the order is done by the secondary_fields which in our case is just the sys_created_on field. So the value of record.order is set to this rather than the integer j.
j++;
record.secondary_fields = [];
options.secondary_fields.forEach(function(key){
if(options.display_field != key)
record.secondary_fields.push(f.meta[key]);
});
record.order = record.secondary_fields[0].value;
For this to work the function getKnowledgeFieldsfromProperties was also simplified just to be
function getKnowledgeFieldsfromProperties(){
//Generate secondary fields based on legacy properties
var fields = [];
fields.push('sys_created_on');
return fields;
}
If you want to have more secondary fields you will need to extend the code to figure out which value in the secondary field array contains the data you want to sort on.
Knowledge List Widget Template
The Body HTML template by adding | orderBy:'-order' as shown below
<div ng-if="c.options.result.length > 0" ng-repeat="item in c.getOrderedItems() | orderBy:'-order' track by item.id" style="margin-bottom: 1em;">
I hope that helps. I couldn't see how the data was being pulled in terms of a GlideRecord where I would usually user to add the required order by.
Kind regards,
Phonsie.