how to display knowledge articles on catalog item form on portal

Karishma Dubey
Tera Expert

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!

4 REPLIES 4

Rafael Batistot
Mega Patron
Want to reduce your ticket volume? In this tutorial, we show you how to configure Contextual Search on a ServiceNow Record Producer. Learn how to set up the Search Assist variables, configure the Search Context, and map it to your form fields. We demonstrate how typing a keyword like "Email" can ...

RaghavendraGund
Tera Guru

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

 
html
<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

 
javascript
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

 
javascript
(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











Tanushree Maiti
Tera Patron

Hi @Karishma Dubey 

 

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

 

This video shows how to add contextual knowledge search in catalog item.

AndersBGS
Tera Patron

Hi @Karishma Dubey 

 

For sure, you should add the contextual search to the single catalog items.