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

May be you should pass the sys_kb_id in the Data Fetch script and use it in Search page template.

You should be able to control it from the Search Source.

 

find_real_file.png


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

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

Hi Susan,

 

I'm new to using servicenow portal, could you give me advise.
My current requirement to include the Knowledge Base selected after doing portal search.

If I've already selected a specific Knowledge Base, my expected search result should only be within that knowledge base.

Any inputs would be much appreciated.

Thanks!