Custom typeahead search bar and how to add options to it

Shane Grayson
Tera Contributor

Good morning Fellow ServiceNow Developers,

 

Issue:

We have a custom header for our Employee Center Portal that uses the default "Typeahead Search" widget. When we run a search, the results, especially for Knowledge Articles, are not what we want. We added the same search widget to the portal page and got the same poor results. However, when we set the "Search Results Configuration" option to "Service Portal Search," the results improved.

 

In the widget's server-side code, it looks like they manually add options. I want to manually add the "Service Portal Search" Data Field option in the server-side code. I tried something like this:

 

typeAheadOptions.search_results_configuration = 'Service Portal Search';

 

I did not get the desired results. I am really not sure how to add it manually to the options like this since they are part of the 'Fields' section of the 'Data Table' found in the Typeahead Search widget, but not in the Header widget.

 

HTML code where the widget gets called:

 

<sp-widget widget="data.typeahead"></sp-widget>

 

Server Side code that is setting options:

 

var typeAheadOptions = {};
typeAheadOptions.refresh_page_on_search_submission = false;
if ($sp.isAISearchEnabled())
  typeAheadOptions.disable_all_suggestions = ($sp.getParameter('disableAllSuggestions') == 'true');

data.typeahead = $sp.getWidget('typeahead-search', typeAheadOptions);

 

Request:

How can I add this Field option 'search_results_configuration' from the Data Table 'Instance with Search [sp_instance_ais]' to the widget being called?

 

Thanks.

1 REPLY 1

Stephen Moore
Tera Expert

I'm trying to do the same thing except replace the Placeholder text but to no avail. Commenting to see if you find a solution.