Fix the Semicolon in a macro expression for a visibility condition in a list of options

Duncan Koza asked on October 13, 2020 17:21

I only want 4 user roles to see a specific option in my drop-down list (form control). I currently have it working for two roles. See below:

1;General

2;Human Resources

3;Library

4;Long-Term Care

5;Long-Term Care ONLY;{%(CurrentUser.IsInRole(".SJCG-Seniors_Health", false)) || (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))#%}

6;St. Joseph's Foundation

7;Wellness @ Work

But, I need it to work for 2 more roles. I want my macro above to look like the one below but the semicolon I am using to seprate the role names is causing me grief, any sugestions?

{%(CurrentUser.IsInRole(".SJCG-Communications;.SJCG-PowerUser;.SJCG-Seniors_Health", false)) || (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))#%}

Recent Answers


Juraj Ondrus answered on October 14, 2020 09:15

I am using this macro {%CurrentUser.IsInRole("CMSEditor;CMSDesigner", false)#%} and it is working fine. What does the macro debug say? I would try not using the dot "." as the first character in the role code names - maybe this is what is confusing the macro syntax. How did you managed to have the dot as a first character? It is not allowed through the UI to create code name to start or end with a dot.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on October 16, 2020 16:37

I think the dot "." automatically gets added because they are global roles. The role code name doesn't actually have a dot "." in the name. The dot just seems to get added when I am in the rule designer.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on October 16, 2020 16:55 (last edited on October 16, 2020 17:00)

I just tried to remove the dots "." and I get the same error. Here is a screen capture of my error.

Image Text

Looks like I wasn't able to link to an image. Here is the link instead.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 19, 2020 05:38

The code name field validation does not allow dots as a starting character at all, it does not matter whether the roles are global or not. No code name should start with dot. Maybe the roles were create through the code or importing.
Thank you for the screen shot - it is more clear now. If you want to use macro expression, then you need to select "Macro expression" option for the drop down list data source. When using List of options, plain text is expected and macros are not resolved.
When using macro expression, it has to be one expression, in your case IF-ELSE and the false branch will return enumerable object for the users not in given roles and true branch will return all the option for users in these roles. It might be maybe easier to create a custom macro method which will return the desired enumeration.

0 votesVote for this answer Mark as a Correct answer

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