hide the comments in kb article

mdeepu433
Tera Contributor

hi guyz...

plz help me

i dont want to show the users comments to the other users but they are able give their own comments for knowledge article portal

find_real_file.png

1 ACCEPTED SOLUTION

Hello m deepu,


1) The portal should primarily be for end users.   Admin and knowledge users will still have access to comments on the back end regardless.



2) If you do decide that you want these users to be able to see comments in the portal regardless you will have to replace the commented out lines with a new div that shows / hides conditionally.   Your new ng-if is going to be paired with whatever data you want from the server.   You can use the below link, and have access to the entire users record to determine the condition.



http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0




In my first example I allowed only the Finance department to see the comments putting the logic into the ng-if.   And in the second example allowed only admin and change managers to see the comments keeping the logic in the server script.



Department:


Screen Shot 2017-12-01 at 8.53.51 AM.png




Roles:


Screen Shot 2017-12-01 at 9.21.35 AM.png



Using a combination of the server script and ng-if condition, you can get the boolean you need to conditionally show or hide the comments.



text of the needed lines:


HTML:


<div ng-if="data.hasRole">


...


</div>



Server script:


var myUserObject = gs.getUser();


data.hasRole = (myUserObject.hasRole('admin') || myUserObject.hasRole('change_manager'));



Or :


<div ng-if="data.dept == '{sys_id of dept here}'">


...


</div>



var myUserObject = gs.getUser();


data.dept = myUserObject.getDepartmentID();



Best,


Andrew


View solution in original post

6 REPLIES 6

Andrew Wortham
Kilo Guru

Hello m deepu,



Unfortunately the comments are baked into the widget.   You can edit the instance options, but if you select not to show user comments it removes the ability for the users to add comments as well.   You would have to clone the widget, I created a custom widget called kb article hide comments.



Luckily, all the comment html is at the bottom and lumped together.



While you could change the client / server script to not pull the data, the simplest / quickest way to achieve what you are looking for is just to not show it, which involves 7 new characters to your widgets HTML!



Screen Shot 2017-11-30 at 3.32.11 PM.png



Please let me know if you have any questions!



Best,


Andrew


Screen Shot 2017-11-30 at 3.36.05 PM.png


Forgot to provide the view of the end result


thank you andrew,



one more thing, is there any way to show those comments for admins.and for some roles??


i mean end users not able to see the feedback comments....


Hello m deepu,


1) The portal should primarily be for end users.   Admin and knowledge users will still have access to comments on the back end regardless.



2) If you do decide that you want these users to be able to see comments in the portal regardless you will have to replace the commented out lines with a new div that shows / hides conditionally.   Your new ng-if is going to be paired with whatever data you want from the server.   You can use the below link, and have access to the entire users record to determine the condition.



http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0




In my first example I allowed only the Finance department to see the comments putting the logic into the ng-if.   And in the second example allowed only admin and change managers to see the comments keeping the logic in the server script.



Department:


Screen Shot 2017-12-01 at 8.53.51 AM.png




Roles:


Screen Shot 2017-12-01 at 9.21.35 AM.png



Using a combination of the server script and ng-if condition, you can get the boolean you need to conditionally show or hide the comments.



text of the needed lines:


HTML:


<div ng-if="data.hasRole">


...


</div>



Server script:


var myUserObject = gs.getUser();


data.hasRole = (myUserObject.hasRole('admin') || myUserObject.hasRole('change_manager'));



Or :


<div ng-if="data.dept == '{sys_id of dept here}'">


...


</div>



var myUserObject = gs.getUser();


data.dept = myUserObject.getDepartmentID();



Best,


Andrew