Hi! So I am building an app and, based on one attribute of the User, I want to change the display of the menu (Set some things invisible). So, I created a Bollean Variable and set it default to false. Then, on Containers that I want to change i set the display to variable. Then, on Extend Properties i create this " style =
If(IdentifierToInteger(GetUsers.List.Current.User.Attribute1) = 1, "ShowContainer = True", "ShowContainer = False")
"
It ALWAYS says that ShowContainer is false, It doesn´t matter If I login as somenone with Attribute1 = 1 or someone with Attribute1 = 2.
Please help me, thanks!
Hello!Additional to the answer already given: Instead of creating a boolean that determines whether the container should be visible or not, you could write your logic directly into the "Visible" attribute of the container. You can use the extended properties to define the style of a container based on a variable that you set somewhere else, e.g. in an action. But you can not change the value of a local variable in the extended properties.
hey! My Container doesn´´'t have the property "Visible"
Does it work for the property "Display"?
Yes, I can put that on "Display" but it didn't work. I logged in with someno with Attribute 1 = 1 and it did not work...
Hi Goncalo,
There are two approaches to achieve your scenario:
1) In the Display property of your container, you can directly paste following condition:
IdentifierToInteger(GetUsers.List.Current.User.Attribute1) = 1
2) In the second, you can use If condition to over screen to invisible container
If(ShowContainer = True)
True
{
// Place container here with Display property set to True
}
False
//Leave empty
Hope it helps, Thanks
Already have done that. The problem is that he always think that Attribute1 is diferent than 1, I don´'t know why
Can you share a sample OML with us to check what is exactly going wrong?
It is not recommened to use an If with "True" and "False" as results. Since a boolean expression already results in True or False, an If like this:
If(a = 1, True, False)
is exactly equal to:
a = 1
Her you go. Menu is in the "Common" folder and the elementes i want to "hide" already have the code
How do you filter your aggregate result for the currently logged in user? It looks like the "GetUsers" aggregate in the menu returns all db entries. And in that case the GetUsers.List.Current.User.Attribute that you´ re checking for, will be taken from the 1st entry no matter of the current end user.
So how should I filter?
Hi Gonçalo,
You can encapsulate the container in an if widget.
Or in Extend Properties... Instead of
put
If(IdentifierToInteger(GetUsers.List.Current.User.Attribute1) = 1, "", "display:none")
But CSS inline is not recommended... because
CSS and HTML should be kept separate. Inline styles are inefficient, harder to maintain, and make your HTML larger.
I hope the above is useful to you!
Hey! Tryied it.. Did not work...
For the mentioned use-case the best implementation approach as per my understanding would be to conduct the server-side validation i.e. Server-side check, whether the logged-in user can access the menu option or not.
In order to implement the same (i.e. server-side check) then as mentioned by Mário, you will have to use the IF widget i.e. Wrap the Menu option within the IF widget with the valid condition. The IF widget (condition) is examined/executed/rendered in the server-side.
IF Widget Condition:
For the mentioned use-case, defining the extended style property as well as defining the container widget's Display/Visible property is not that secure and is not considered as good practise. Let's say that the widget Display/Visible property is set to False value, in that case what happens under the hood is a inline-style i.e. style=" display: none;" is defined to the respective html element, which can be easily edited using the Browser inspect element feature. Hence, the restricted end-user can also access the menu option with a small tweak.
Hope this helps you!
Kind regards,
Benjith Sam