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

thanks for the snaps i need to check


A Kose
Tera Contributor

Hi there @Andrew Wortham and @mdeepu433

thank you for this information, is there anyway to hide public comments on knowledge articles that are older than 1 year. I tried to update the UI Macro but it didn't generate the expected results, do I have to update the portal view edit the widget 'Knowledge Article Comments' to achieve this, I am new to ServiceNow so any help would be appreciated. thanks a million