1172
Views
5
Comments
Solved
How to check if value is in list, on expression editor?
Question

Hello! 

I know there is a lot of ways to check if a value is in a list, but not in expression editor, this may be confusing so I will explain the problem.

When I open the page, I load all of the user areas. And depending on what areas the user has, he can or not see some stuff in the page...
Let's say I have a button to add something, and I only want to show it to the user, if area admin is in the list.
How do I achieve this? I already read other questions in this forum but I didn't find an approach to my problem.

All the help is appreciated! :)

2021-06-02 20-50-04
Márcio Carvalho
Solution

Each problem has different "paths", so you need to think about your logic. From what I could understand.

To check something from a list. You can use the action ListIndexOf, it will return the position of what you are trying to find, and if don't find it, it returns -1. So there you go, if is -1 is because area admin is not on the list, so you will not show the button. You need to see where to do this, before rendering the screen. On a data action. In whatever way, you just need to have an output saying area admin to identify when to show or not the button.

ListIndexOf

I think you can also use the List Any:



If you are getting or using a list, I think you should do this on a data action or onAfterFecth of an aggregate where you are getting data. 

2021-12-29 03-29-46
Ricardo Figueiredo

So either way, I have to always have some kind of boolean to make that check, wich means if I have 10 areas, I have 10 booleans... And I have place true or false in them while loading those areas...
I didn't want to do that, doesn't seem sustainable, but seems the only way... :/

2026-01-26 10-25-31
Lennart Kraak
Champion

Alternatively you could create a function that gets the UserId and desired AreaId as input parameters. This function can then check if the UserId has access to that AreaId and return True of False.

2021-06-02 20-50-04
Márcio Carvalho

Is like you are doing a check for a role. In this case, you pass the UserId and the area(using the static record that matches in this case admin) and when using the button you call that function that will check if the user has access to the "role" in this case area admin and returns false or true as you said. I advised you to not check with string, check with something that is stored on your database, I don't know, maybe a static? In this way, in the future, you don't have to check every screen for all those strings that you use to compare! Because they are all stored on the static, and any change of area name you just need to go change the static and everything ok. It's like the same for URLs ✌️ 

2023-10-13 10-00-13
Heba AbdElmonaem

I solve this Problem by add inline function and make a loop on this function around list like this 

1-use loop because can not use system function like list index or list append or like that on inline function
2-Then use this function on expression editor 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.