The CreatorCon Call for Content is officially open! Get started here.

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! 

0 REPLIES 0