How to hide comments field if doesnot belong to particular group in native KB UI

Jay N
Tera Contributor

Hi Experts,

 

We have a requirement to hide comments field if user doesn't belong to particular group in native KB UI.

May i request experts to share solution

 

JayN_0-1739798828043.png

 

3 REPLIES 3

Martin Friedel
Mega Sage

Hello,

 

There is a checkbox on Knowledge Article called 'Dissable commenting', this dissable comments for all users for particular article. I think this behavior could be also set on Knowledge Base level.

 

To display it for certain users you need to do a customization.

On Portal comments are basically displayed by a widget. Locate correct widget, clone it and include additional condition to Server script logic to display comments block.

For example I found widgets called 'Knowledge Article Comments' or 'KB Article Comments'.

 

  • Specify Portal you need to hide comments in.
  • What is exact condition to hide/display comments to certain users?

Martin

Hi Martin,

Thanks for quick reply, our requirement is not on the serviceportal view, on load of the viewarticle>kb_view, comments should be visible only to particular group.


Thanks, Jay

  • Page 'kb_view.do' is a UI Page located in UI Page table [sys_ui_page] (Sys ID: 11efa742eb4221007128a5fc5206fe1a)
  • To display KB Article data, it uses logic located in Script Include 'KBViewModel()' that extends OOB Script Include 'KBViewModelSNC()'
  • In Script Include 'KBViewModelSNC()', there is a function 
    canShowKBFeedback() that handles logic with validation if comments should be displayed

So you have to customize the logic

 

  1. Open Script Include 'KBViewModel' (SysID: 994116f1d73221004792a1737e610371)
  2. Paste customized function
canShowKBFeedback: function() {
    var showFeedback = gs.getProperty('glide.knowman.show_user_feedback');
    showFeedback = showFeedback.toLowerCase();

    if (showFeedback === 'never' || this.knowledgeRecord.disable_commenting)
        return false;

    var roles = gs.getProperty('glide.knowman.show_user_feedback.roles');
    if (roles != null && roles != '') {
        var hasRole = gs.hasRole(roles);
        if (hasRole == false)
            return false;
    }

    //Add logic with custom condition regarding group member
    var currentUser = gs.getUser();
    var group = 'Allowed group'; // Add your logic to retrieve group

    if (!currentUser.isMemberOf(group)) {
        return false; // Don't display comments section
    }

    return true;
},

 

Before:

comment1.JPG

After:

comment2.JPG

If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin