How to Conditionally Hide/Show Item for Certain Role(s)?

Hi All

As stated in the question. I know I am able to hide/show items depending on the stage of the form.

But what i'm trying to achieve is to hide/show depending on the user role. E.g. show a custom button only to people in "admin" role, but hide it when normal user is accessing the form.

Tried getting it to work by using JavaScript, but it seems that app.getCurrentUser() does not return the user role.

Hope anyone can advise. Thanks in advance!

I had a similar requirement in my App where I had to show a link to few Admin users only. Currently Volt does not return Role of a user. Hopefully Volt team will provide this in future releases. As a workaround, I created another Form to save names of few Admin users separated by semicolon in a field. Then I fetched these user names using Service on the Form where I was supposed to hide/show link. Now using javascript I checked if app.getCurrentUser() is part of fetched Admin users field or not and accordingly hide/show link. I used "indexOf" javascript function for this.

P.S. app.getCurrentUser() returns username in canonical form (CN=Test User\O=company). I used common name (Test User) for storing Admin user names. To get common current username I used below code.

var canonical = app.getCurrentUser();
var indx1 = canonical.indexOf('CN=')+3;
var indx2 = canonical.indexOf('/');
var common = canonical.substring(indx1, indx2);

Looks like a feasible workaround. Will try it out! Thank you.

In order to get this feature, I created an idea:

https://domino-ideas.hcltechsw.com/ideas/VOLT-I-129

Please vote for it to get it considered and done.

The idea is slightly different from what I want to achieve though. It is more of show/ hide based on user role rather than based on stage.

For stage, I believe it could be done with something like below (taken from the documentation):

var actions = form.getStageActions();
for(var i=0; i<actions.length; i++)
     {
     if(get(actions,i).getId() === 'S_Submit')
     {
     get(actions,i).activate();
     break;
     }
     }

But I agree, it has to be more straightforward. And for that I have voted the idea :)

Sorry, I mixed up two things in my last two ideas.

I added the roles to the idea.

Oh yes, I saw the other idea. Upvoted as well. Cheers