Show Knowledge Article based off keyword widget

Evan Duran
Kilo Guru

Hello, I currently have this widget where I want to feature articles only with a certain keyword. How should I go about doing this?
EvanDuran_0-1675063954408.png

EvanDuran_1-1675063963947.png

(function() {
	if(input)
		return;
	else {
	options.aria_label_title = options.title || gs.getMessage('Featured Articles');
	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.reverse = false;

	if(options.display_field != "short_description"){
		options.secondary_fields.push(options.display_field);
	}

	var kbService = new KBPortalService();
	options.knowledge_base = options.knowledge_base || String(kbService.getServicePortalKnowledgeBases($sp.getPortalRecord().url_suffix)) || "";
	var j = 0;
	var result = [];
	var kb = kbService.getFeaturedArticles(options.max_records,options.display_field,options.secondary_fields,options.knowledge_base);
	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','false') == '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','false') == 'true')
			fields.push('author');
		if(gs.getProperty('glide.knowman.search.show_view_count','false') == 'true')
			fields.push('sys_view_count');		
		if(gs.getProperty('glide.knowman.search.show_last_modified','false') == 'true')
			fields.push('sys_updated_on');
		if(gs.getProperty('glide.knowman.search.show_published','false') == 'true')
			fields.push('published');
		if(gs.getProperty('glide.knowman.show_unpublished','false') == 'true')
			fields.push('workflow_state');
		if(gs.getProperty('glide.knowman.search.show_rating','false') == 'true')
			fields.push('rating');

		return fields;
	}
})();

 

1 REPLY 1

Spence90
Tera Contributor

Hi Evan,

 

OOB the system has a property (glide.knowman.default_keyword) that contains the default keyword used to display articles in that widget - homepage

 

Not entirely sure of your ask here, but if you want to use a different keyword other than homepage you can go to that system property and change the Value to something else. I believe the keyword has to be one word.

 

Once you do that, then when you add articles to the Featured Content related list of the knowledge base you can create the new keyword there that matches exactly what was inputted in the system property and they'll start showing up in the Featured Content widget.

 

Keep in mind, other keywords can be created that aren't provided in the default_keyword system property, but those will only allow the articles associated to those keywords to be displayed at the top of search results on the KB Portal search (NOT the global search - the specific search provided on the KB Portal if you're using that).