sn_km_api, can't get results back. Anyone have anymore info on this API or KBPortalServiceImpl

David Nendza
Tera Guru

Background: We are testing connecting CoPilot with ServiceNow, to allow users to ask it questions and to have it respond with information from our knowledgebase. Following most of the steps here: https://www.matthewdevaney.com/copilot-studio-servicenow-connect-knowledge-base-incidents/

The issue is that the connection uses the Knowledge Management Rest API (sn_km_api, https://www.servicenow.com/docs/bundle/zurich-api-reference/page/integrate/inbound-rest/concept/know...) and does a keyword search by default (not sure if we can change the call on the copilot side), and this seems to always return an empty array. I've been trying various things on the SN side with the call and I can't get it to return search results.

 

From what I can see, by default it uses the "Knowledge Search" context by default, and the "knowledge" knowledgebase as the search knowledgebase. I don't understand why this is always returning an empty array. I also tried the same thing on a PDI and get the same result.

Does anyone know what needs to be looked at/corrected to have results be returned on a keyword search?

I've checked the text indexes (they are fine), re-indexed, messed around with search configs.. can't figure it out.


Additional information
The sn_km_api /articles endpoint calls sn_km_api.KnowledgeRestAPIUtil(), utilizing the search function
which calls KnowledgeRestAPIUtilSNC
Which updates the parms and sends it through to global.KBPortalServiceImpl().getResultData(input);
Which updates the parms even more and sends the payload to SNC.SearchRequest().fromJSON(data);
Which is a black box.

example code:

function doKeywordSearch(queryText, count, queryLocation) {
    var results = [];

    // To set up the request.
    var request = {
        keyword: queryText,
        language: "",

        // To pass data to filter on different metadata.
        variables: {
            kb_knowledge_base: ['Knowledge'],
            kb_category: '',
            author: ['']
        },

        // Provide the following.
        context: gs.getProperty('glide.knowman.sp.search_context', 'Knowledge Search'),
        resource: 'Knowledge',
        order: "relevancy,true",

        // Provide the pagination variables.
        start: queryLocation,
        end: queryLocation + count,

        attachment: false,

        // Provide any additional metadata you want to include in your results.
        knowledge_fields: [
            "number",
            "sys_id",
            "published"
        ]
    };

    // To execute the search.
    var response = new KBPortalServiceImpl();
    response.getResultData(request);

    // To send the search results back to the UI or to store results in your object.
    for (var i = 0; i < response.results.length; i++) {
        result = response.results[i];
        var article = {};
        article.sys_id = result.meta.sys_id.display_value;
        article.number = result.meta.number.display_value;
        article.short_description = article.short_description;
        article.title = result.title;
        article.published = result.meta.published.display_value;
        article.publishedUTC = result.meta.published.display_value;
        article.text = article.text;
        article.score = result.meta.score;
        article.label = article.short_description;
        article.shortDescription = article.short_description;
        results.push(article);
    }

    return results;
}

var res = doKeywordSearch("password");
gs.info(res);
res = doKeywordSearch("password", 10, "knowledge");
gs.info(res);

 

0 REPLIES 0