Service Portal Search should split knowledge and catalog items

bsk
Kilo Expert

Q1)Service Portal Search selection should group   knowledge articles and catalog items separate it displays all together now.Is there any way to group them in typeahead search PFA.

Q2) Can any suggest me on how to label Knowledge Article on header and show list of articles below that and similar to label service catalog and catalog list below that .Rather then displaying knowledge article and service catalog for each entry.

test search.PNG

1 ACCEPTED SOLUTION

Thanks for your response i found solution by making some script changes and it worked comunity.PNG


View solution in original post

32 REPLIES 32

chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Santosh,



I was just exploring this change and I found few places where you can modify and get exact same result but I am not sure about the best way to do this, so do it at your risk



Steps:


1.   Open your custom service portal.


2.   Goto Search Sources and open Service Catalog & Knowledge Base records


Screen Shot 2017-06-27 at 5.50.16 AM.png


3. In Service Catalog record, add <strong>Service Catalog: </strong> in Typeahead form section.


Screen Shot 2017-06-27 at 5.53.46 AM.png



4. Now open Knowledge Base   - Search Source record and add article.kb_title = "Knowledge Base: "; at line number 23 ( as described in below screenshot)



Screen Shot 2017-06-27 at 5.55.10 AM.png



5. Open "sp-typeahead.html" Angular Template and add "<strong ng-if="match.model.kb_title">{{match.model.kb_title}}</strong>"


URL : https://instance_name.service-now.com/sp_ng_template_list.do?sysparm_query=id%3Dsp-typeahead.html



Screen Shot 2017-06-27 at 5.58.31 AM.png



That's it and the result :


Screen Shot 2017-06-27 at 5.59.41 AM.png



Note: Please test in your personal dev. instance before implementing.


Thanks for your response i found solution by making some script changes and it worked comunity.PNG


Hi Santosh,



can you please provide steps how you have done? it would be helpful to me




Thanks


nayeem


(function() {


var order = 0;// ordering articles and catalog


data.searchType = $sp.getParameter("t");


data.results = [];


      data.searchMsg = gs.getMessage("Search");


data.limit = options.limit || 15;


var textQuery = '123TEXTQUERY321';




if (!input)


return;




data.q = input.q;


getKnowledge();


if (gs.isLoggedIn())


getCatalogItems();


data.sqandaEnabled = gs.getProperty('glide.sp.socialqa.enabled', false) === 'true';


if (data.sqandaEnabled)


getQuestions();




// add in additional search tables from sp_search_groups


var portalGR = $sp.getPortalRecord();


var portalID = portalGR.getDisplayValue('sys_id');


var sg = GlideRecord('sp_search_group');


sg.addQuery('sp_portal',portalID);


sg.addQuery('active',true);


sg.orderBy('order');


sg.query();


while (sg.next())


addSearchTable(sg);




// typeahead search generates multiple "Your text query contained only


// common words..." msgs, we don't want them


gs.flushMessages();




function addSearchTable(sg) {


var table = sg.getValue('name');


var condition = sg.getValue('condition');


var gr = GlideRecord(table);


if (condition)


gr.addEncodedQuery(condition);




gr.addQuery(textQuery, data.q);


gr.query();


var searchTableCount = 10; // serach count


var header = {};     // begin header label for catalog and article


header.type="header";


header.label = "<h4>"+sg.tables.getDisplayValue()+"</h4>";


header.score = 0;


header.order=order;


header.text= sg.tables.getDisplayValue();


data.results.push(header);


order++;     // end


while (gr.next() && searchTableCount < data.limit) {


var rec = {};


rec.type = "rec";


rec.table = table;


rec.sys_id = gr.getDisplayValue('sys_id');


rec.page = sg.getDisplayValue('sp_page');


if (!rec.page)


rec.page = "form";


rec.label =     "<b>"+table+"</b> "+gr.getDisplayValue(); // displaying label


rec.score = parseInt(gr.ir_query_score.getDisplayValue());


rec.order=order;   // order begin


data.results.push(rec);


searchTableCount++;


order++;   // order   end


}


}




function getKnowledge() {


var kb = new GlideRecord('kb_knowledge');


kb.addQuery('workflow_state', 'published');


kb.addQuery('valid_to', '>=', (new GlideDate()).getLocalDate().getValue());


kb.addQuery(textQuery, data.q);


kb.addQuery('kb_knowledge_base', $sp.getDisplayValue('kb_knowledge_base'));



kb.query();


var kbCount = 10;   // count list


var header = {};                               // begin header label for   article                    


header.type="header";


header.label =   "<h4>Knowledge Article</h4>";


header.score = 10;


header.order=order;


header.text= "Knowledge Article";


data.results.push(header);


order++;                                   //order end




while (kb.next() && kbCount < data.limit) {


if (!$sp.canReadRecord(kb))


continue;




var article = {};


article.type = "kb";


$sp.getRecordDisplayValues(article, kb, 'sys_id,number,short_description,description,picture,published,text');


if (!article.text)


article.text = "";


article.text = $sp.stripHTML(article.text);


article.text = article.text.substring(0,200);


article.score = parseInt(kb.ir_query_score.getDisplayValue());


article.label = "<b>Knowledge Article</b> " +article.short_description; // highlight KB in bold fornt of KB article


article.order=order;     // order begin


data.results.push(article);


kbCount++;


order++; // order ends




}


}


function getCatalogItems() {


var sc = new GlideRecord('sc_cat_item');


sc.addQuery(textQuery, data.q);


sc.addQuery('active',true);


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


sc.addQuery('visible_standalone', true);


sc.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');


sc.addQuery('sc_catalogs', $sp.getValue('sc_catalog'));


sc.query();


var catCount = 10;// limit the search to 5


      var header = {};             // begin of header and label for catalog


header.type="header";


header.label = "<h4>Service Catalog</h4>";


header.score = 10;


header.order=order;


header.text= "Service Catalog";


data.results.push(header);


order++;


while (sc.next() && catCount < data.limit) {


if (!$sp.canReadRecord(sc))


continue;




var item = {};


if (sc.getRecordClassName() == "sc_cat_item_guide")


item.type = "sc_guide";


else if (sc.getRecordClassName() == "sc_cat_item_content") {


var gr = new GlideRecord('sc_cat_item_content');



gr.get(sc.getUniqueValue());


$sp.getRecordValues(item, gr, 'url,content_type,kb_article');


item.type = "sc_content";


}


else


item.type = "sc";



$sp.getRecordDisplayValues(item, sc, 'name,short_description,description,picture,price,sys_id');


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


item.order=order;     //order begin


item.label = item.name;// highlight SC in bold infront of catlog name ("Service Catalog "+)


data.results.push(item);


catCount++;


order++;   // order ends


}


}


function getQuestions() {


var questionGR = new GlideRecord("kb_social_qa_question");


questionGR.addActiveQuery();


questionGR.addQuery(textQuery, data.q);


questionGR.query();


var qCount = 0;


var header = {};     // begin of header for questions


header.type="header";


header.label = "<h4>Questions</h4>";



header.score = 0;


header.order=order;


header.text= "Questions";


data.results.push(header);


order++;



while (questionGR.next() && qCount < data.limit) {


if(!$sp.canReadRecord(questionGR))


continue;




var question = {};


question.type = "qa";


$sp.getRecordDisplayValues(question, questionGR, 'question,question_details,sys_created_on,sys_id');


question.text = (question.question_details) ? $sp.stripHTML(question.question_details) : "";


question.text = question.text.substring(0,200);


question.label = "<b>Question</b> "+question.question;


question.score = 0;


question.order=order;     //order begin


data.results.push(question);


qCount++;


order++;       // order ends


}


}


})();


Thank you so much....