How to populate short description along with the number when searched in the homepage search widget of a service portal ?

sumana1707
Mega Contributor

Dear All,

I am very new to service portal. Please let me know how to populate short description along with the number when searched in the homepage search widget of a service portal ?

For example. if I give INC039.... , it should populate all the incidents stating with INC039... alond with the short description placed beside the incident number.

It should be applicable for REQ, KB, TASK etc also.

I appreciate all the help from you.

Regards,

Sumana

1 ACCEPTED SOLUTION

Manoj Kumar16
Giga Guru

Hi Sumana,



You need to create a scripted Data Source for the Incidents. In the scripted Data Source add



(function(query) {
var results = [];
//Here goes the logic. Compute results however you want!
if (!gs.isLoggedIn())
return results;




var inc = new GlideRecordSecure('incident');


inc.addQuery('123TEXTQUERY321', query);


inc.addQuery('active',true);


inc.addQuery('no_search', '!=', true);


inc.addQuery('caller', gs.getUserID());


inc.query();


var RowCount = 0;


while (inc.next() && RowCount < data.limit) {


var item = {};


item.type = "inc";


item.page = "ticket";




$sp.getRecordDisplayValues(item, inc, 'number,short_description');



item.score = parseInt(inc.ir_query_score.getDisplayValue());


item.label = item.number;


item.desc=item.short_description;


item.primary = item.number;


item.id=item.sys_id;


item.url = '?id=' + item.page +'&table=incident'+'&sys_id=' + inc.getUniqueValue();



results.push(item);


RowCount++;


}


return results;


})(query);




In this article you will find how can you use the Advance Typeahead Template to put whichever fields you want to dsplay


Create an advanced typeahead template



Create the advance typeahead template -



<span ng-bind-html="match.label | uibTypeaheadHighlight:query"></span>    


<span ng-bind-html="match.model.short_description | uibTypeaheadHighlight:query"></span>



Please note the text marked in BOLD in both scripts, In this way you add whichever field you want to display.


View solution in original post

13 REPLIES 13

Shane J
Tera Guru

I didn't set this up but it's currently working as I think you are looking for.   So to update your widget:



  1. Go to your Search widget on the main Service Portal page, hold CTRL and right-click it.
  2. Choose 'Widget in Editor' from the menu that comes up.
  3. In the HTML Template box we have the following (I think the bolded section is what you are looking for):


<div id="homepage-search" class="hidden-xs wrapper-xl">


  <div class="wrapper-xl">


      <img src="servicenow_logo_portal.png" class="sn-logo"/>


  <h1 class="text-center text-4x sp-tagline-color" ng-bind="options.title"></h1>


  <h4 ng-if="options.short_description" class="text-center m-b-lg sp-tagline-color" ng-bind="options.short_description"></h4>


  <sp-widget widget="data.typeAheadSearch" />


  </div>


</div>


Thank you for your reply. I have checked the steps, you suggested and found it already present in our instance. But whenever, I am searching with INC... , it is only showing up the incident numbers but i want the short description also, to be populated along with the incident, means in the result list there will be the number and the appropriate short description placed beside the number.


find_real_file.png


This should be applicable for INC, REQ, TASK, KB etc.


Please let me know in case of any further query.



Regards,


Sumana


Manoj Kumar16
Giga Guru

Hi Sumana,



You need to create a scripted Data Source for the Incidents. In the scripted Data Source add



(function(query) {
var results = [];
//Here goes the logic. Compute results however you want!
if (!gs.isLoggedIn())
return results;




var inc = new GlideRecordSecure('incident');


inc.addQuery('123TEXTQUERY321', query);


inc.addQuery('active',true);


inc.addQuery('no_search', '!=', true);


inc.addQuery('caller', gs.getUserID());


inc.query();


var RowCount = 0;


while (inc.next() && RowCount < data.limit) {


var item = {};


item.type = "inc";


item.page = "ticket";




$sp.getRecordDisplayValues(item, inc, 'number,short_description');



item.score = parseInt(inc.ir_query_score.getDisplayValue());


item.label = item.number;


item.desc=item.short_description;


item.primary = item.number;


item.id=item.sys_id;


item.url = '?id=' + item.page +'&table=incident'+'&sys_id=' + inc.getUniqueValue();



results.push(item);


RowCount++;


}


return results;


})(query);




In this article you will find how can you use the Advance Typeahead Template to put whichever fields you want to dsplay


Create an advanced typeahead template



Create the advance typeahead template -



<span ng-bind-html="match.label | uibTypeaheadHighlight:query"></span>    


<span ng-bind-html="match.model.short_description | uibTypeaheadHighlight:query"></span>



Please note the text marked in BOLD in both scripts, In this way you add whichever field you want to display.


Thank you Manoj. Your answer resolved the issue



Regards,


Sumana