Get role of user

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • yuri
    replied
    Indeed, roles are not loaded for the current user. Maybe consider using a custom field instead? It can be enum, multi-enum or link. Cannot be link-multiple as they are not loaded there.

    Leave a comment:


  • onepoint0
    replied
    Hi Yuri,

    I'm trying to do this too. When I create a custom view for my entity I find that this.getUser().attributes.rolesIds is undefined and when I console log it I get the attributes object (correct username, email etc) but it doesn't contain the roleIds property:

    Code:
    "recordViews": {
        "detail": "custom:views/record/camera-detail"
    },
    
    ....................
    
    define('custom:views/record/camera-detail', ['views/record/detail'], function (Dep) {
        return Dep.extend({
      
            setup: function () {
                Dep.prototype.setup.call(this);
                console.log(`camera detail custom view `,this);
                // const hasRole = (this.getUser().attributes.rolesIds || []).includes(targetRoleId);
                console.log('role = ',this.getUser().attributes.rolesIds); // <-- undefined
            },
    
        });
    });
    My user definitely has a role:

    Click image for larger version  Name:	user-role.png Views:	0 Size:	36.7 KB ID:	116159

    Am I doing this wrong?
    Last edited by onepoint0; 03-24-2025, 02:32 AM.

    Leave a comment:


  • yuri
    replied
    Within a view:

    Code:
    const hasRole = (this.getUser().attributes.rolesIds || []).includes(targetRoleId);
    Within any other class, need to inject the user: https://docs.espocrm.com/development...ncy-injection/

    Leave a comment:


  • abhilash.kumar.niit
    replied
    hi, can any one help in this ?? i also have same requirement.

    Leave a comment:


  • BigBoss
    started a topic Get role of user

    Get role of user

    Hello,
    How can I get if the authenticated user in the JS files and also the role?​​
Working...