Pinned knowledge in Contextual Search Results

Dan Brown2
Kilo Sage

Hi,

I have created some 'Featured Content' for knowledge bases and when searching from the knowledge base homepage it pins it to the top of the results.   This is great, but is there anyway to have this pinned to the top of the Contextual Search Results on the Incident form etc too?

Cheers,

Dan

1 ACCEPTED SOLUTION

Aditya Mallik
ServiceNow Employee
ServiceNow Employee

If you are using the out of the box "incident deflection" Search Context, then system would render the pinned articles on the Contextual Search Results.



Basically you need to ensure that the Search Context that you are using, is associated with a Searcher that includes Pinned Knowledge articles.


View solution in original post

16 REPLIES 16

Yes it is possible, with a bit of customization. I will ask Cameron to respond on his reply.


Appreciate it, Aditya.


Hi Dan,



I've got something for you to try out. I assumed that you want to do something to the whole result row (tr) of a given pinned article. It doesn't make for the best CSS selector as there is no way to get the row directly. The code will iterate over all the pinned articles (they're always first) and break as soon as the source isn't "pinned".



Add the script bellow to your form as an onLoad client script. The event it observes is fired by Contextual Search whenever there is an update; that update could be results or no results.



Let me know how you get along.



function onLoad() {


      document.observe("cxs:target_update", function() {


              if (!NOW || !NOW.cxs_searchService || !NOW.cxs_searchService.response || !NOW.cxs_searchService.response.results)


                      return;


             


              var results = NOW.cxs_searchService.response.results;


             


              for (var i = 0; i < results.length; i++) {


                      if (!results[i].meta.pinned)


                              break;


                     


                      var elem = $$(".cxs_result[data-index=" + i + "]")[0].up(".list_row");


                      elem.setStyle({


                              backgroundColor: "blue"


                      });


              }


      });


}



Thanks,



Cameron


Hi Cameron,



Thanks for taking the time to assist here.



When creating a new incident, I have added it as a onChange to the Short Description field and it works ok there.  



When opening a current incident that has already been raised, it doesn't work there.



Any advice?



Thanks again,



Dan


Hey Dan,



Sorry....I realised that my response last night was only part of the solution. I was just editing it when you responded.



Have a look at it again and it should answer your question.