Is there a way to hide a drop down option based on the user?

  • 0
  • 2
  • Question
  • Updated 2 years ago
  • Answered
I have a mutli-choice drop down with Item A, Item B, Item C. I would like to hide Item C for people who are in a particular role. Is this possible? 
Photo of Stephony (DBH)

Stephony (DBH)

  • 586 Points 500 badge 2x thumb

Posted 2 years ago

  • 0
  • 2
Photo of QuickBasePros_IDS

QuickBasePros_IDS, Champion

  • 2,266 Points 2k badge 2x thumb
Not within a standard multiple-choice drop down.  However; if you created a table of those options you could then permission roles based on records meeting a criteria; so their "drop down" selections would be restricted to the ones you want them to see.

You would create a table-to-table relationship between your "option list" and your main table to make selections.  Consider making the key field of that table the name, unless it's possible for those options to change name values.
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
A low tech option is to have a form rule
When multiple conditions are true
User is in the role particular
Choice is C

Action:
Change choice to blank

uncheck that checkbox at the bottom so that the rule always fires.

So its not hidden but the user won't be able to choose it and have it stick.
A third approach would be to use Javascript. This is the most powerful and flexible way to do it, but it takes some technical know-how. If you use Dan Diebolt's Image Onload technique to load a Javascript file whenever your form is opened, you can use simple jQuery to remove options easily based on user roles.

You can find out all the app's roles and the way they're represented numerically by looking at the source HTML of any QuickBase form. Search for roleinfo. The roles the current user is assigned to are held in a global variable called gReqUserRoleIDs.

Let's imagine you want to remove Item C from the dropdown for Field ID# 6 for anyone in the Assistant role. You learn from the HTML of a form that the Assistant role has a numerical value of 20. Write a few lines of Javascript like the following and save it as a code page:
(function() {
    // check to see if the current user is in the Assistant role, number 20
    if (gReqUserRoleIDs.search("20") !== -1) { // string.search() returns -1 if the search term isn't found, meaning, in this case, that the user is in role 20
         $("select#_fid_6 option:contains('Item C')").remove();
    }
})();
Next, create a formula text field that will get a Javascript file using the Image Onload technique (if you're not familiar with this, just do a search for it). Add the field to your form, and Bob's your uncle. If a user opens the form who has role 20, Item C will be removed from the dropdown for Field ID# 6.
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,804 Points 5k badge 2x thumb
Hi Phillip,

Thank you for sharing this here. I will try this in one of my scenarios. :)

Thanks,
Gaurav
(Edited)
Photo of Stephony (DBH)

Stephony (DBH)

  • 586 Points 500 badge 2x thumb
Thank you!