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

Hi!



Your solution works wonders for our customers Portal when searching for catalog items!



However, if the "Short Description"-field is empty, the typeahead returns "null". Do you know how to remove "null" when the field doesn't contain any text?



Regards,


Eivind Sandnes


Hi Eivind,



In the Scripted Data Source of the incident you can see there is a line-



item.desc=item.short_description;



Replace it with-



if(item.short_description==''||item.short_description==null)


item.desc="empty"; // Add whatever text you would like in the quotes, if you want to leave it blank then keep it blank


else


item.desc=item.short_description;



In the advanced typeahead template you can see i have added match.model.short_description



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



Replace 'short_description' with 'desc'



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


Thanks for the help!



We're trying to add the short description for Catalog Items, so that bit of code isn't there.


A colleague gave me a tip that seems to work, we added an "ng-if" at she start of "match.model" for short description.


Do you see any problem with that?



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


Manoj Kumar wrote:



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.



Can you please implement the same for REQs and RITMs?



Thanks in Advance....!!!


Hi Manoj,


I have a same requirement to show Short description beside Incident number in search result. I have followed same process and created a search source with same code that you provided still i am not able to get the result. Is there anything else I need to configure on search source or on search widget.