Catalog Item Widget that Relates to Knowledge Article

Kev9
Kilo Sage

Hi,

In Service Portal I'd like a widget in my knowledge article that shows sc_cat_ items related to that article. I'd guess there'd need to be some relationship between the meta in the article and the cat item but can't really figure out how to do this.

Can anyone offer suggestions?

Many thanks.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

So your post was interesting to me and I had been working on this over the past 2 days, but didn't get a chance to post until just now.

So I built out a custom widget that will query the knowledge article's metadata and then query your catalog item's metadata and if any term matches between the two, it'll show the "related catalog item" for the user to simply click and it takes them right to the form to fill out.

Obviously this is just for Service Portal, but this should help ease the user's experience and make things pretty fluid.

To accomplish what I did, you'd need to go to: Service Portal > Service Portal Configuration > Widget Editor and then click create new widget. Name it whatever you'd like and then in each of these sections, copy and paste the code from below:

HTML

<sp-panel ng-if="data.items.length > 0" >
  <ul class="list-group">
    <li class="list-group-item" ng-repeat="a in data.items">
      <a href="?id=sc_cat_item&sys_id={{::a.sys_id}}">{{::a.name}}</a>
      <div>
      </div>
    </li>
  </ul>
</sp-panel>

CSS

.transclude:last-child {
  padding-bottom: 10px;
}

.list-group {
 	margin-bottom: 0px; 
}

.list-group-item {
    padding: 0;
    border: none;
    margin-bottom: 10px;
    border-radius: 0px;
}

.list-group-item:last-child {
	margin-bottom: 10px;
}

Client Script/Controller

function() {
  /* widget controller */
  var c = this;
}

Server Script

(function() {
	data.items = [];
	options.title = options.title || gs.getMessage("Related Catalog Items");
	
	var sys_id = $sp.getParameter('sys_id');
	var kbmeta;
	
	if(sys_id != null ){
		var gr = new GlideRecord("kb_knowledge");
		if(gr.get($sp.getParameter('sys_id'))){ 
			data.kbmeta = gr.getValue('meta');
			kbmeta = gr.getValue('meta').toString().split(',');
		} else
			 return false;	
	}
	runscript(kbmeta);
})();

	function runscript(kbmeta) {
	var relatedItems = [];
	var gr, i;
	for (i = 0; i < kbmeta.length; i++) {
	gr = new GlideRecord('sc_cat_item');
	gr.addQuery('meta', 'CONTAINS', kbmeta[i]);
	gr.addQuery('sys_id', 'NOT IN', relatedItems);
	gr.query();
	while (gr.next()) {
		if (gr.getRowCount() > 0) {
		relatedItems.push(gr.sys_id+'');
		var a = {};
		$sp.getRecordValues(a, gr, 'name,short_description,sys_id'); 
		data.items.push(a);
   }
  }
 }
}

now click "Save".

Now, go to Service Portal > Service Portal Configuration > Designer and click the page for the Knowledge Articles (where you wanted this to show) - for me I put it on the kb_article page. Once you're on that page in designer mode, simply find the widget along the left-hand side and drag and drop it where you want it to show on the page. Once it's there...hover your mouse over it and click the pencil icon, like so:

find_real_file.png

Now you can clean it up a bit more and add a Title and Bootstrap Color (like I chose title of Related Catalog Items and bootstrap of Primary).

Once you're all finished it should look something like this:

find_real_file.png

So the user would then just click on relevant catalog item. I have several showing as an example, but I assume you'd really only have like 1 or 2 maybe 3 showing as far as matching metadata.

Tested and working in Madrid too, by the way!

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

21 REPLIES 21

SatheeshKumar
Kilo Sage

you need to build a custom widget to place list of items in article page.

for linking article with catalog item there is a OOB table for a different functionality. but you can use the same for yours.

check widget for usage:HRI Catalog to KB Article Display (need HR module to access this)

check table : sc_2_kb

also check the below link for reference:

https://docs.servicenow.com/bundle/madrid-hr-service-delivery/page/product/human-resources/task/link...

 

-satheesh

 

We don't have the HR module unfortunately

then you need a custom table to store the mapping information OR alternatively tou can add an additional field in sc catalog item table to store the required details

Hi SatheeshKumar,

I want to configure "Related Catalog items" widget on my portal but while i am doing it by clicking "Page In Designer" and searching "Related Catalog items" widget i am not getting . do i need to activate any pluging ? actually i am adding this new york feature to my outdated instance how to get it?

Secondly, I have gor the "Related Articles" i have also added some articles but i am not able to get them on the portal why?

please help me out with these two queries.

Thanks,