Service Portal - Change Sequence of Search Results

JimCheffer
Kilo Expert

The Service Portal search results return in this sequence.

find_real_file.png

We would like to change the sequence (Left Box) to Service Catalog, Knowledge Base and Question and Answers. Also the search results (list window on right) in the same sequence. Our goal is to direct users to the Service Catalog first. I found sys.properties "glide.service_portal.default_search_sources" and changed it to the sequence we want but it does nothing or is overwritten.Thanks in advance. Jim

1 ACCEPTED SOLUTION

You would have to clone and modify the Search Page widget.



In the HTML template, change:


<div role="listitem" ng-repeat="item in data.results | orderBy:'score':true | limitTo:data.limit" class="panel-body b-b ">


to


<div role="listitem" ng-repeat="item in data.results | limitTo:data.limit" class="panel-body b-b ">



In the server script, add orderBy call to this piece of code:


} else {


var m2mSearchSourceGR = new GlideRecord("m2m_sp_portal_search_source");


m2mSearchSourceGR.orderBy('order'); // <<-- ADD THIS LINE


if (data.t)


m2mSearchSourceGR.addQuery("sp_search_source.id", data.t);


m2mSearchSourceGR.addQuery("sp_portal", $sp.getPortalRecord().getUniqueValue());


m2mSearchSourceGR.query();


while(m2mSearchSourceGR.next()) {


var searchSourceGR = m2mSearchSourceGR.getElement("sp_search_source").getRefRecord();


data.resultTemplates["sp-search-source-" + searchSourceGR.getValue("id") + ".html"] = $sp.translateTemplate(searchSourceGR.getValue("search_page_template"));


getResults(searchSourceGR);


}


}


View solution in original post

15 REPLIES 15

Hello Nia, thanks for the code. Works as you indicated. My first customization on SP. You may see more questions. Jim


Sorry picture is worth showing. Left panel sequence we wanted and right side too. We may revisit. I like the scoring option but time will tell.


find_real_file.png


Would this also resolve the popup window below the Search Box on the homepage of the portal?




We have the same issue, but it's affecting the popup box under the homepage search box (We have an Access Request catalog item buried under Knowledge Articles):



find_real_file.png



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

Hi Steven,



No the above code would not change the way the popup works.   For that, I believe you'd have to modify the Typeahead Search widget in a similar fashion as above.   The key is modifying the search code to respect the order:



m2mSearchSourceGR.orderBy('order'); // <<-- ADD THIS LINE


Though, i haven't actually tried this. You might also want to consider what effect this has on the ordering of results by relevance before you change anything, as I believe that's the default.


I just noticed it appears there is a problem ticket open for this:



ServiceNow KB: Search results displayed out of order in Service Portal when using non-scripted searc...



With included, and I assume updated, widgets attached to it.



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