Service Portal: Custom Homepage Search Widget

Alex Harrill
Tera Expert

I'm attempting to customize a copy of the Homepage Search widget. The original is currently on the homepage of our Service Portal. It searches the Catalog, Knowledge Base, and Users.
For the copy, I want it on a different page as the company directory. So it would only show Users and exclude the Knowledge Base and Catalog search sources. Below is the copied widget code I tried to modify:

HTML:
<div id="homepage-search" class="hidden-l wrapper-l">
<div class="wrapper-l" style="padding: 5px;">
<h2 class="text-center text-4x m-b-lg sp-tagline-color" ng-bind="options.title"></h2>
<div ng-if="options.short_description" class="text-center h4 m-b-lg sp-tagline-color" ng-bind="options.short_description"></div>

<!-- Display only the "Users" search source -->
<sp-widget widget="data.typeAheadSearch" source="'Users'" />
</div>
</div>

Server Script:
var aisEnabled = $sp.isAISearchEnabled(); if (aisEnabled) { // Fetch the "Users" search source data.typeAheadSearch = $sp.getWidget('typeahead-search', options); data.typeAheadSearch.sources = data.typeAheadSearch.sources.filter(function(source) { return source.name === 'Users'; }); } else { data.typeAheadSearch = $sp.getWidget('typeahead-search', options.typeahead_search); }

This still displays all the search sources.
I'm a bit of a novice when it comes to ServiceNow, so I'd love to hear any feedback on this! Thanks!

2 REPLIES 2

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Alex Harrill 

Its nothing to do with widget / script. You need to define the search sources. You can refer below

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/task/add-table...


Please mark as Accepted Solution / Helpful if you get it 🙂

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Alex Harrill
Tera Expert

Hi @Sohith1,
I may have not been clear, so I apologize.
The Homepage Search widget is on our Service Portal homepage. I want to use the same widget on a different page of the same Service Portal. I've already defined the 3 search sources I've mentioned above.
But maybe I'm not understanding what you mean, if you don't mind elaborating 

 

 Thank you!