Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Search page widget link page

ryanwoodburn
Kilo Expert

Hi

I would like to change the page I am taken to when I select a result from the "search page" widget.

I have used Search Sources, and populated the page I would like to go to Under Typeahead > page.


This works if I select the search result from the typeahead search preview.

However, if I submit the search I am taken to the search page, which contains the search page widget mention above to list the results.

Does anybody know how to change the destination when I click on a result in this widget?

I am currently taken to the Form page.   If I inspect the search page widget I can see this set as a href:

find_real_file.png

I do not know how this is defined though.

Thanks

4 REPLIES 4

teamcarl
Mega Expert

Hi Ryan,



You can set the target page within the Search Page widget itself.



For a KB article, for instance, you can change the href within the HTML Template:



<div ng-if="item.type == 'kb'">


              <a href="?id=putyourpagehere&amp;sys_id={{item.sys_id}}" class="h4 text-primary m-b-sm block">



Or for a catalog item, you can change the 'item.page = "putyourpagehere";' section in the Server Script.



Hope that helps,



Carl.


Hi Carl



So I have four search sources / types - 3 of which are record tables (inc, Chg, Prb) and 1 is the service catalog.   The service catalog is working well.



My html skills are limited - can you show me exactly where you would add:



<div ng-if="item.type == 'kb'">


              <a href="?id=putyourpagehere&amp;sys_id={{item.sys_id}}" class="h4 text-primary m-b-sm block">




The part of the script you need I imagine is:


<div ng-if="data.results.length>0" class="panel-heading break-word">


          <h2 class="h4 panel-title">${Search results for '{{data.q}}'}</h2>


      </div>



<div role="list" >


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


              <div ng-include="item.templateID"></div>


          </div>


      </div>


  </div>


</div>



Below is the result widget inspected.   I need if I change the id to my page in that URL it works perfectly, I just don't know how to do that in the html



find_real_file.png


Thanks


Hi Ryan,



So, apologies, it looks like the OOTB widget is very much amended in Jakarta from Helsinki (which is what we're on).



This might now be a crude way to do it, but it does work:



find_real_file.png



So, for example, pasting the following code in underneath the <div role="listitem" ng-repeat="item in data.results | orderBy:'score':true | limitTo:data.limit" class="panel-body b-b "> line would sort the KB redirect:



<div ng-if="item.type == 'kb'">


              <a href="?id=yourpage&amp;sys_id={{item.sys_id}}" class="h4 text-primary m-b-sm block">


                  <i class="fa fa-book m-r-sm"></i>


                  <span ng-bind-html="highlight(item.short_description, data.q)"></span></a>


              <p ng-bind-html="highlight(item.text, data.q)"></p>


              <span class="text-muted">${Article}: {{item.number}}</span>


              <span class="text-muted">


                  <span class="m-l-xs m-r-xs"> &middot; </span>


                  ${Published}: <sn-day-ago date="item.publishedUTC"/>


              </span>


          </div>


Community Alums
Not applicable

Hi Ryan,

 

I think there is an esay to solve your issue.
You can go your search source.

find_real_file.png

And then, in the Search page template:

I think you have something like this: <a href="?id=form&

So you need to put: <a href="?id=kb_article&

 

Olivier