Need help for View Knowledge topic in Virtual Agent[VA]

Admin7267
Kilo Sage

I have a requirement to create a topic: View KB, if user selects that then VA should display the list of KB categories then base on users selection of KB category, VA needs to display the KB article under that category.

 

I have created an SCRIPT INCLUDE

var KnowledgeCategoryScriptInclude = Class.create();      // KnowledgeCategoryScriptInclude
KnowledgeCategoryScriptInclude.prototype = {
   initialize: function() {},
   getCategories: function() {
      var categoryList = [];
      var gr = new GlideRecord('kb_category');
      gr.query();
      while (gr.next()) {
         categoryList.push({
            id: gr.getValue('sys_id'),
            name: gr.getValue('name')
         });
      }
      return categoryList;
   },
   type: 'KnowledgeCategoryScriptInclude'
};

 

And SCTIPTED REST API

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
   var kbScriptInclude = new KnowledgeCategoryScriptInclude();
   var categories = kbScriptInclude.getCategories();
   response.setBody(categories);
})(request, response);

 

SCRIPT in Virtual Agent

var restEndpoint = 'REST_API_ENDPOINT/KnowledgeCategoriesAPI/categories'; 
var response = new sn_ws.RESTMessageV2();
response.setHttpMethod('GET');
response.setEndpoint(restEndpoint);
response.execute();
var responseBody = response.getBody();
var categories = JSON.parse(responseBody);
 if (categories.length > 0) {
   var categoryMessage = 'Here are the available KB categories:\n';
   for (var i = 0; i < categories.length; i++) {
      categoryMessage += (i + 1) + '. ' + categories[i].name + '\n';
   }
gs.info(categoryMessage);
} else {
gs.info('No KB categories found.');
}

 

But I don't see that it's not at all working. 

2 REPLIES 2

Adam Chapman
Tera Guru

Are you stuck on something or just looking for someone to do your work for you? What is you have so far?

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Can you share where exactly you need help with? For example share what you tried already, what is working already, and where you are stuck, and where you really need help with.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn