Kentico Datasource list of options hide option depending on role

Tom Wisneski asked on June 9, 2020 03:20

Is it possible to hide a dropdownlist option depending on the current user's role? Thinking of a Macro expression to hide a specific dropdownlist option. Using a Custom Table Alternate form > Data Source > List of options.

Correct Answer

Juraj Ondrus answered on June 9, 2020 19:14

So, you have basically two sets of options. One contains 2 items and the other one contains 3 options. You want to display one when condition is true and the other when false. So, when using macro expression, the expected returned result is some enumeration list - so the list of options will be filled into the drop down. The true part of the condition will return one set of options, the false part of the condition will return the other set of options.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on June 9, 2020 07:31

Yes, you can use the macro expression to fill out the drop down list values and use a condition there to check the current user's role. For example something like this:

if (CurrentUser.IsInRole("RoleCodeName")==true) {< enumObject >} else {< enumObject2 >}

1 votesVote for this answer Mark as a Correct answer

Tom Wisneski answered on June 9, 2020 14:44 (last edited on June 9, 2020 14:46)

Juraj, a follow-up question. So a little confused on this...so say there are three options in the dropdownlist; Industrial, Mobile, Clean Energy. The last (Clean Energy) is the one that only a given role should be able to view. So do you add the other two using the same type of Macro syntax you gave as an answer (if (CurrentUser.IsInRole("RoleCodeName")==true) {< enumObject >} else {< enumObject2 >}), or do the first to get added as List Options and then the last uses the Macro. Sorry for the confusion, just not sure. Thank you :)

0 votesVote for this answer Mark as a Correct answer

Tom Wisneski answered on June 9, 2020 20:02

Juraj --Thank your for the updated explanation...this makes more sense. Thank you!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.