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

Are you able to post your entire server script? I think you need to attach the accountOrders to the data object. So- data.accountOrders = true;