Search Sources: Paginate is not working when following the example

Dan142
Giga Expert

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/task/pagina...

 

When following the above example, the code below does not display any results:

(function(query, queryLocation, count) {
  var results = [];
  /* Calculate your results here. */
  var userGR = new GlideRecord('sys_user');
	userGR.addQuery('active', true);
	userGR.addQuery('name', 'CONTAINS', query);
	userGR.query();
	
	userGR.setLocation(queryLocation - 1);
	
	var resultCount = 0;
	while(userGR.next() && resultCount < count + 1){
		var obj = {};
		obj.sys_id = userGR.getUniqueValue();
		obj.primary = userGR.getDisplayValue();
		obj.query_location = userGR.getLocation();
		obj.label = userGR.getDisplayValue();	
		results.push(obj);
		resultCount++;
	}
	
	if(results.length == 0)
		return results;

	if(results.length > count) {
		results.pop();
	} else {
		// In order to indicate that a result in the result
		// set is the final result (that there are
		// no more results to be fetched), add this property
		// to the final element in your result set.
		results[results.length - 1].isLastResult = true;
	}
  return results;
})(query, queryLocation, count, facets);

 

The typeahead works but the results page does not.

Why is it not working?

1 ACCEPTED SOLUTION

The search facet needed to be enabled.


https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/task/enable-facets.html

View solution in original post

6 REPLIES 6

Did this get resolved?

Was a ticket opened with SeriveNow?

 

I spent a few hours thinking I was doing something wrong only to find this article later.

In addition, our company built a store app that needs a scripted search to work with paging.

Store apps are not allowed to make changes to global files.

 

So, b/c this wasn't working I had to do the following:

  • Clone the Faceted Search Widget
    • correct the line of code in the widget that isn't updating the page
  • Clone the search page (we were using an OOTB page also)
    • update to use the cloned Faceted Search Widget above
  • Clone the Type Ahead Search Widget
    • This has the search page to use hard coded in it
  • Change our portal page to use the cloned type ahead search widget that directs users to the new cloned page
We will update this post with the ticket and PBR and KB when they are created so this can be tracked by the community.

ServiceNow has informed us that this will be resolved in the Washington release.