For service portal search sources, how can we change which parameters are used in Typeahead Search results?

SusanWinKY
Kilo Sage

We're using typeahead search for knowledge articles but want to display those using the kb_article_view page.  After the London upgrade, we are seeing that our typeahead search results for knowledge articles are using the same URL format...

https://instance-name.service-now.com/sp?id=kb_article_view&sys_id=6dbe8137db8f678024f0f6e9af961979

but the kb_article_view page isn't able to handle the sys_id parameter, so we are getting a "Knowledge record not found" message.  We need to be using the sys_kb_id parameter instead of sys_id. 

We're using the OOB Knowledge Article Content widget on that page.  In my personal developer instance, I was able to trick the widget into using the sys_id parameter if it can't find a sy_kb_id parameter.  I replaced line 224 of the server script with this code:

 data.params.sys_kb_id = $sp.getParameter('sys_kb_id');
data.params.sys_id = $sp.getParameter('sys_id');
if((data.params.sys_id != '' && data.params.sys_id != null) && (data.params.sys_kb_id === '' || data.params.sys_kb_id === null))
     data.params.sys_kb_id = data.params.sys_id;

(Please don't judge my code; I'm not much of a script-er.)

It seems the OOB widget should be able to handle either parameter.  Anyway, our problem still remains that we don't see a way to change which parameter is used by the search results returned during a typeahead search.  It's always using sys_id.  Any suggestions on how this can be done?


Susan Williams, Lexmark
1 ACCEPTED SOLUTION

SusanWinKY
Kilo Sage

I found an article in the London docs that explains how to do this but there is an error in their code, which I have reported via feedback.

 

It looks like the London article (didn't check any other version) on the ServiceNow docs site has an incorrect value being used for the sys_kb_id value in the article URL.

In step 1-c, the code should be this:

article.url = "?id=kb_article_view&sys_kb_id=" + article.sys_id;

instead of this:

article.url = '?id=kb_article_view&sys_kb_id=' + kb.sys_id;

 

In summary, here's what I did to get this to work:

1. Updated the Search page template as Mark suggested above, because we want both the typeahead search and the regular search results to use the kb_article_view page...

<a href="?id=kb_article_view&amp;sys_kb_id={{item.sys_id}}" class="h4 text-primary m-b-sm block">

2. Updated the Data fetch script as mentioned in the docs article but corrected it to article.sys_id...

article.url = "?id=kb_article_view&sys_kb_id=" + article.sys_id;

3. Updated the Page on the Typeahead tab to kb_article_view.  This is not required but we want to have it shown there as a visual reminder that we are using the kb_article_view page instead of kb_article.


Susan Williams, Lexmark

View solution in original post

7 REPLIES 7

SanjivMeher
Kilo Patron
Kilo Patron

Is kb_article_view an OOB page? Because I can't find it. It may be a custom one created by your team.


Please mark this response as correct or helpful if it assisted you with your question.

Yes, it comes with the Knowledge Management - Service Portal plugin.


Susan Williams, Lexmark

Community Alums
Not applicable

Hi Susan,

 

Refer to this blog. Please mark it helpful if that solved your purpose.

https://community.servicenow.com/community?id=community_blog&sys_id=de5ce6a1dbd0dbc01dcaf3231f96194a

 

Yes, I've read both of those blogs before. 

The Typeahead tab on our Knowledge Base search source is very similar to the OOB one except we selected a different glyph and are using the kb_article_view page. 

find_real_file.png

 

But nowhere do I see how to update which URL is used when clicking a result in the typeahead search results list.  It doesn't seem this is something to be done with the Advanced typeahead config either.  I am looking at the OOB one for the Service Catalog search source and just see formatting. 

Where is the URL defined for typeahead search?  I'm hoping this is something simple I am missing.

find_real_file.png


Susan Williams, Lexmark