Global Variables for hiding stuff

I want to hide specific components for some user groups.
Users in the permission group "admin" or "superuser" can see everything others dont.
For that I use this formula:
{{current_user.groups.filter((g)=>{return"admin" ||"superuser"}).length===0 }}

My question now is, is it possible to write this formula in some sort of global variable so that I can use it in every App? for example I call the variable "isSuperUser" and when I want to hide something I put this variable in the hidden field.

I don't think the configuration (aka global) variables work that way, they're more for strings and secrets like API keys etc. and if you put the formula into that it won't evaluate it (afaik)

Queries can be reused (but not ALASQL ones which would be perfect here) but formulas like this I don't think have that option. I tend to put any "global" stuff like this in a module that's on every page, like the navbar etc.

you could use the Query Library which would let you reuse it wherever you want as a Query Resource:


I didn't think you could use the Query JSON as SQL (alasql) queries as library though?

my bad, you're right. I had never tried heh

could you put that function in the advanced settings for preloaded js?

window.isSuperUser = (groups) => !groups.some(g => === "admin" || === "superuser")

then call it in app like

window.isSuperUser({{ current_user.groups }})

I didn't try it, just pondering if it would work


Great Idea!
I put below function in the preloaded JS:
function isSuperUser (user){return user.groups.filter((g)=>{return"admin"||"Superuser"}).length===0};
In my hidden field I then can use {{window.isSuperUser(current_user)}}
Very Nice Thanks a ton @khill-fbmc !

1 Like