- 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-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
‎11-20-2019 02:11 AM
Hi Allen A,
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2019 03:53 AM
Have you created the widget? It's not OOB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2019 09:26 PM
In my personal instance which is already in New York have catalog item widget but my another instance which is upgraded to New York does not have this widget so i manually have created the same i did correct or i need to raise a high ticket for this OOB widget?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 01:26 AM
There's no OOB widget to do this as far as I'm aware, you need to create a new one using the code and script from Allen A.
Once you've created the widget place it on the kb_article page.
You need to have matching meta in the article and your Catalog Item for the widget to appear.