Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to hide the Tab in record page in workspace.

u499207
Tera Contributor

Hi All,

I am working on a Configurable Workspace page in UI Builder where I have multiple tabs, including a Playbook tab. My requirement is to show the Playbook tab only for users who have a specific role.

Role:
xyz

Requirement:

  • If the logged-in user has the above role, the Playbook tab should be visible.
  • If the user does not have the role, the Playbook tab should be hidden.

What I Tried:

  1. I added a visibility script in the Playbook tab settings in UI Builder.
function evaluateProperty({api}) {
    if (api.user.hasRole('xyz')) {
        return true;
    }
    return false;
}
  1. I also tried checking user roles using:
function evaluateProperty({api, helpers}) {
  let user_roles = api.context.session.user.roles;
  let visibility_condition = user_roles.includes('xyz');
  return visibility_condition;
}

Issue:
Even after applying the script, the Playbook tab is still visible for users who do not have the role.

Questions:

  1. Is the tab visibility controlled differently in Configurable Workspace?
  2. Is there a recommended way to restrict tab visibility by role?

Any suggestions or best practices would be helpful.

Thanks in advance.

Anitha P

1 ACCEPTED SOLUTION

@u499207 ,

It returns true means ,the user contains the role xyz, then the tab will be visible.If the user doesn't contain the role means it will return false,then tab will get hidden.

Check out with the user who are not having xyz role.

If my response helped,mark it as helpful and accept the solution.

View solution in original post

7 REPLIES 7

Dinesh Chilaka
Kilo Sage

Hi @u499207 ,

You did everything correct but in ServiceNow UI Builder if you are working on Visibility,

returning true - refers to hide the component.

returning false - refers to show the component.

So change the small thing in your script,

function evaluateProperty({api, helpers}) {
  let user_roles = api.context.session.user.roles;
  let visibility_condition = user_roles.includes('xyz');
  return  !visibility_condition;
}

 While returning visibility_condition just return !visibility_condition.
If my response helped, mark it as helpful and accept the solution.

u499207
Tera Contributor

Hi @Dinesh Chilaka ,
Thanks for the response,
Tried with the above mentioned script still it not working as expected (for all the users playbook tab is hiding).

Thanks,
Anitha P


 

@u499207 ,

Ok.could you share the screenshot where you are writing the script?

 

Thanks,

Dinesh

Hi @Dinesh Chilaka ,
please, find the screenshot below.

Thanks,
Anitha