Is there a way to get an enitity's name from itself in a server action ?
We have a generic validation routine that needs to know the entity its processing, as of now we just feed it the entity name "hardcoded" in a parameter. Obviously, this will break if we refactor.
Is there any way to get an entity's name with a function, reflection, demonic incantations, etc. ?
Hello @Francois Gaudet
We have to take dependency from systems module where all of the data is available in entities.
I hope this will help
Thanks
Tousif Khan
So, given an entity, how do I get it's name ?
Hello Francois,
Unfortunately, I don't know any Demonic Incantation for this, but if you want I can show you one that calls forth adorable kittens out of the Void! :D
Now back to your issue, the entity dependency that Tousif mentioned in the post above is a list of all the entities present on your Service Studio.
With this, you can get the name of all the Entities.
Now, looking at this from a pragmatic point of view I would suggest creating an Auxilary Entity to store the name of the Entities you need to validate, something like:
And just use this table on your validation logic. This will allow you to only validate the ones that you need and keep things more decupled in case of a refactor.
Hope it helps!
Paulo Rosário
Hi @Paulo Rosário 👨🏽🚀,
I'm (slightly) familiar with the OutSystems meta-model, and getting info about an entity given it's name... The issue is getting its name from itself... ie: myEntityNameIs = GetVarTypeName(ThisEntity).
I think @Dorine Boudry has what I'm looking for !
Hi Francois,
i have made a forge asset to do model based validations, and to do that I needed to know the name of an entity to look it up in the systems table. Probably very similar to what you guys are setting up.
So look at this component, I made a server action called "WhatAmI" that returns the name of an entity, given a variable of that entity. You pass in ToObject(yourEntityVariable) and you get out the name.
That sounds pretty close to what you are looking for.
Dorine
EDIT : i just had a look, and apparently it is possible to define this as a function, so you can do this :
Hi @Dorine Boudry, that sounds exactly like what we're looking for!
I'll have a look at that, thanks!