Service Portal: Hide a button based on logged in users roles?

Julia Howells
Giga Guru

I have a button in the portal that needs to be hidden if the logged in user does not have a specific role. Here is my button HTML: 

 

 

 <button
      type="button"
      class="btn btn-dash {{c.data.view.account == true ? 'selected' : 'unselected'}}"
      ng-click="accountOrders()"
      id="btnB">
      Account Orders
      
      </button>

 

 

And then in the Server Script, I have the following script, but the button is not hidden for anyone:

 

 

		if (
      gs.getUser().hasRole(''admin')
    ) {
      accountOrders = true;
    } else {
			accountOrders = false;
		}

 

 

ideas?

1 ACCEPTED SOLUTION

Elijah Aromola
Mega Sage

You can try: 

<div ng-show="c.data.accountOrders">
     <button
          type="button"
          class="btn btn-dash {{c.data.view.account == true ? 'selected' : 'unselected'}}"
          ng-click="accountOrders()"
          id="btnB">
          Account Orders
     </button>
</div>

View solution in original post

5 REPLIES 5

Elijah Aromola
Mega Sage

You can try: 

<div ng-show="c.data.accountOrders">
     <button
          type="button"
          class="btn btn-dash {{c.data.view.account == true ? 'selected' : 'unselected'}}"
          ng-click="accountOrders()"
          id="btnB">
          Account Orders
     </button>
</div>

Hi Elijah,

This hides the buttons for admins as well (where they should see it based on the server script - I think??)

That might be because your code has a typo. Change your server script to:

if (gs.getUser().hasRole('admin')) {
     accountOrders = true;
} else {
     accountOrders = false;
}

No luck, sadly.

JuliaHowells_0-1677177121166.png

 

JuliaHowells_1-1677177156894.png

Buttin still isn't available for admins in the Portal.