Inside the Power Platform JavaScript Development Course: Using Security Roles

One of the things that we JavaScript developers do fairly frequently is to make decisions based on security role.

It could be something as simple as showing or hiding a field, section, or tab, or it could be as complicated as turning off Command Bar buttons.

One of the accelerator code libraries, that is part of my Power Platform JavaScript Development course, is code that allows you to retrieve the current user’s security roles (by name), then use those roles to make decisions.

Here is how it is implemented:

const currentUser = {
    isSalesManager: MyLibrarySecurity.userHasRole("Sales Manager"),
    isMarketingManager: MyLibrarySecurity.userHasRole("Marketing Manager")
};
 
if (currentUser.isMarketingManager) {
        // do things specifically for the Marketing Manager security role
    }
 
if (currentUser.isSalesManager) {
        // do things specifically for the Sales Manager security role
    }

More than a bit of work went into making this work, but work it does.

Join the course today to see how it is done.

Drop me a line if you have any questions.

Thanks, Mitch

Leave a Reply 0 comments