how to display knowledge articles on catalog item form on portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I want to display related knowledge articles when user type something in short description field of catalog form. Is it possible to achieve.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
May you use Contextual Search
https://youtu.be/5MYOU6Qszfs?is=qSXX6X7QDgOQJqkX
This helps other users find accurate and useful information more easily
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello @Karishma Dubey
Yes, This is Feasible I tested it on my PDI.
There's no OOB Solution - A regular cat.item doesn't show Knowledge articles when the user types in a variables, I even tried with contextual search , There's no existing contextual search table for any catalog table. I tried to create one but the UI type only offers Platform and Workspace, No portal option(Refer Screenshot 1)
So, i created a widget first
Name: KB Suggestions | ID: kb-suggestions
HTML Template
<div ng-if="c.articles.length" class="panel panel-default">
<div class="panel-heading">Related articles</div>
<ul class="list-group">
<li class="list-group-item" ng-repeat="a in c.articles">
<a ng-href="?id=kb_article&sys_id={{a.sys_id}}" target="_blank">
{{a.number}} - {{a.short_description}}
</a>
</li>
</ul>
</div>Client controller
api.controller = function($scope, $rootScope, $timeout) {
var c = this;
c.articles = [];
var pending;
$rootScope.$on('field.change', function(evt, parms) {
if (parms.field.name != 'short_description') return;
if (pending) $timeout.cancel(pending);
pending = $timeout(function() {
var term = parms.newValue || '';
if (term.length < 3) { c.articles = []; return; }
c.server.get({ action: 'search', term: term }).then(function(r) {
c.articles = r.data.articles;
});
}, 400);
});
};Server script
(function() {
data.articles = [];
if (input && input.action == 'search' && input.term) {
var kb = new GlideRecordSecure('kb_knowledge');
kb.addQuery('workflow_state', 'published');
kb.addQuery('valid_to', '>=', gs.now()).addOrCondition('valid_to', 'ISEMPTY', '');
kb.addQuery('123TEXTQUERY321', input.term);
kb.setLimit(5);
kb.query();
while (kb.next()) {
data.articles.push({
sys_id: kb.getUniqueValue(),
number: kb.getValue('number'),
short_description: kb.getValue('short_description')
});
}
}
})();Next Step 2: Add it to your catalog item
On your catalog item, add a new variable:
- Type: Custom
- Order: higher than your Short description variable
- Type Specifications tab > Widget: KB Suggestions(Refer Screenshot2 &3)
If your variable isn't named short_description, change that name in the client controller.
Step3:
Open your catalog item in the portal, type a keyword that matches a published article in Short description, then press Tab. Below are the things i noticed
- Use $rootScope.$on('field.change'), not $scope.$on. With $scope, the widget never received the change, and nothing appeared.
- Results appear after the user finishes typing and leaves the field (Tab or click away), not on every keystroke.
- The search checks article content as well as titles, so related how-to articles also show up.
Refer Screenshot4 for the final result
If my reply helped, please mark it as Helpful and Accept as Solution
Regards
Raghavendra G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
You can check how to add contextual search for your catalog item :
https://www.youtube.com/watch?v=_hWb6yTDUmk
https://www.youtube.com/watch?v=_hWb6yTDUmk
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
For sure, you should add the contextual search to the single catalog items.
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
