- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 11:16 PM - edited 01-10-2023 11:18 PM
Hi Team,
Please help with the customization of the Server Script for the Typehead search widget, so that it only searches Record producer's items.
Currently, it searches all visible KB articles, requests, etc. needs to restrict these searches & allow to search only Record Producer items.
Please help with this ask.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 01:43 AM
@rishabh31 you will not need script modifications for this
go to your portal page and update search source correctly. and make sure TypeHead is enabled in search source
Bharath Chintala

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 11:53 PM
Hi,
Go to the portal and add search source.
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 10:32 AM
Hi @Rahul Kumar17 pls help to customize below server script of the typehead search to only search record producer items
(function() {
var portalRecord = $sp.getPortalRecord();
data.aisEnabled = $sp.isAISearchEnabled();
data.q = $sp.getParameter('q');
if (options.refresh_page_on_search_submission == undefined)
data.refreshPageOnSearch = true;
else
data.refreshPageOnSearch = options.refresh_page_on_search_submission;
// AI Search
if (data.aisEnabled) {
data.searchApplicationId = options.search_application || portalRecord.getValue('search_application');
gs.addInfoMessage(data.searchApplicationId);
options.placeholder = options.placeholder ? gs.getMessage(options.placeholder) : gs.getMessage('Search');
data.aiSearchSourceFilter = "";
var aiSearchSource = options.ai_search_source_filter;
var filterGr = new GlideRecord('sys_search_filter');
filterGr.addQuery('name','sc_cat_item');
filterGr.addQuery('ais_search_source', aiSearchSource);
filterGr.addQuery('search_context_config', data.searchApplicationId);
// filterGr.addQuery('search_context_config','test');
filterGr.addActiveQuery();
filterGr.orderBy('order');
filterGr.query();
if (filterGr.next())
data.aiSearchSourceFilter = filterGr.getUniqueValue();
var portalId = portalRecord && portalRecord.getUniqueValue();
var resultMap = $sp.getAISearchResultsActionConfig(data.searchApplicationId, portalId);
// var resultMap = $sp.getAISearchResultsActionConfig('test', portalId);
resultMap = JSON.parse(resultMap);
data.tableToSourceMap = resultMap.tableToSourceMap;
data.sourceToPageMap = resultMap.sourceToPageMap;
data.urlMap = resultMap.urlMap;
return;
}
if (input && input.action === "GlideSPSearchAnalyticsUpdateRank") {
input.action = "";
var textSearchAnalytics = $sp.publishSearchAnalytics(JSON.stringify(input.payload));
return ;
}
if (options.title) {
options.title = gs.getMessage(options.title);
}
data.resultMsg = gs.getMessage("Search results.");
data.navigationMsg = gs.getMessage("To navigate, use up and down arrow keys.");
data.portalID = $sp.getPortalRecord().getUniqueValue();
data.searchMsg = gs.getMessage("Search");
data.noResultsFoundMsg = gs.getMessage("No results found");
data.isSuggestionsEnabled = gs.getProperty('glide.search.suggestions.enabled');
data.searchTypeBehavior = gs.getProperty('glide.service_portal.search_as_you_type_behavior').toLowerCase();
data.typeaheadWaitMS = getIntProperty('glide.service_portal.typeahead.wait_ms', '1000');
data.typeaheadMinLength = getIntProperty('glide.service_portal.typeahead.min_length', '3');
data.isLocationTrackerDisabled = gs.getProperty('glide.service_portal.disable_location_tracker');
var searchSources;
data.searchType = null;
data.searchSources = [];
if ($sp.getParameter("id") == "search" && $sp.getParameter("t")) {
data.searchType = $sp.getParameter("t");
searchSources = $sp.getSearchSources(data.portalID);
} else {
var contextualSearchSourceIDs = options.contextual_search_sources || null;
searchSources = $sp.getSearchSources(data.portalID, contextualSearchSourceIDs);
if (searchSources.length == 1) {
data.searchType = searchSources[0].id;
}
}
data.searchSourceSysIds = [];
data.typeaheadTemplates = {};
data.searchSourceConfiguration = {};
searchSources.forEach(function(source) {
data.searchSourceSysIds.push(source.sys_id);
if (source.isTypeaheadEnabled) {
data.searchSources.push(source.id);
}
var sourceTemplateConfiguration = {
sys_id: source.sys_id,
glyph: source.typeaheadGlyph,
linkToPage: source.typeaheadPage
};
if (source.isAdvancedTypeaheadConfig) {
sourceTemplateConfiguration.type = "ADVANCED";
sourceTemplateConfiguration.template = "sp-typeahead-" + source.id + ".html";
data.typeaheadTemplates["sp-typeahead-" + source.id + ".html"] = $sp.translateTemplate(source.typeaheadTemplate);
} else {
sourceTemplateConfiguration.type = "SIMPLE";
if (!sourceTemplateConfiguration.linkToPage)
console.log("Warning: No typeahead page or URL provided for search source " + source.name);
}
data.searchSourceConfiguration[source.id] = sourceTemplateConfiguration;
});
function getIntProperty(name, defaultValue) {
var answer = parseInt(gs.getProperty(name, defaultValue));
return isNaN(answer) ? defaultValue : answer;
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 01:43 AM
@rishabh31 you will not need script modifications for this
go to your portal page and update search source correctly. and make sure TypeHead is enabled in search source
Bharath Chintala