- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2019 09:24 AM
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.
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2019 09:07 AM
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:
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:
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2019 01:35 AM
Allen A,
That's fantastic! Works brilliantly. Thank you very much.
Regards,
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 01:04 PM
Curios. Firstly, Allen, I think your work was nice! Thank you.
Secondly... I've struggled with this idea since we moved to SN from another KM tool.
Would it not be WISER to have a relationship between the KB Category, and the Service Catalog or CI?
I do see a reason to have the Catalog as yet another separate item, but if we have
- a tool or service, supported by the company, orderable by the user...
and we've got a Knowledge article supporting the same tool, or service...
we should have a 1:1 relationship between the 2, so users could lookup "all articles about product or service X"... so that if that product or service changes, the articles could also be triggered to change, or stuff like that... trackable relationships.