Displaying specific topics/categories to users

Jerry20
Tera Contributor

We are looking to display specific topics/categories in the pull down list of the knowledge home page to users based on an a setting in the audience field of the knowledge form and user type in the user record.   Currently we filter articles using ACL's with the combination of the audience field and user type field but we cannot control what selection of topics/categories is available for selection

8 REPLIES 8

Jerry20
Tera Contributor

Thanks everyone, this helps as I have a few options to try


Jerry20
Tera Contributor

Slava, I'm trying your approach.   Referring to your statement var topics = $$("table.kb_main div[dragpart=Applications]");   what table are you referring to?   Your example is for one topic which is hard coded.     I'm trying to separate Agent and Employee therefore it looks like I will need a table that defines topics that belong to an Agent and topics that belong to employee's.   Can you give me a few more details on what you mean by which table in the statement you are referring to?   If I need to use an alternate table that defines who should see the topics, can you help?


In this context, the word "table" does not refer to a database table. What we are actually doing here is manipulating the HTML DOM (Document Object Model) of the page.



Each block on KB home page is a <div> with the name of the topic/category in the dragpart attribute. Expression inside the brackets is a CSS selector that simply finds a <div> with the relevant value of the dragpart attribute inside a <table> tag that has class = "kb_main".



Instead of hard-coding the name of the topic that needs to be hidden, you can add some code in the beginning to determine it based on attributes of the user or anything else and then pass it to your function as a parameter.


Here is a very rough draft of the UI script. You will need to use GlideAjax to make a call to a script include where you can define all your logic for hiding topic/categories.



addLoadEvent(function() {


      if(location.href.indexOf('/kb_home.do') != -1 && location.href.indexOf('jvar_view_topic') == -1) {


           


              // Use GlideAjax here to make a call to a script include


              // that will determine which topics need to be hidden...


              //


              // http://wiki.servicenow.com/index.php?title=GlideAjax


           


              var ga = new GlideAjax('GetTopics');


              ga.addParam(...);


              ga.addParam(...);


              ga.getXML(MyCallBackFunc);


           


              function MyCallBackFunc(response) {


                      myTopic = 'name_of_the_topic';


                      hideTopic(myTopic);


              }



      }


});



function hideTopic(t) {


      var topics = $$("table.kb_main div[dragpart=" + t + "]");


              if(topics.length > 0)


                      topics[0].hide();


}