16
Views
11
Comments
Solved
Read attribute from dynamic name
Application Type
Traditional Web, Mobile, Reactive, Service
Service Studio Version
11.9.0 (Build 32956)

Hi,

I'm trying to get access to an attribute value from a string name.

For example :

Let's assume we an aggregate on a User entity which return one user and it's attributes.

The syntax to return the username will be someting like "GetUserById.Current.User.Username"

What I'm trying to do is set the name of the attribute in a variable and access it dynamically, in an expression with a syntax like this :

GetUserById.Current.User.[MyAttribute]

Where the local variable MyAttribute has for value "Username".


Unfortunately it's not working. Is there a way to do it ?

Thanks!

Rank: #70
Solution

Hi Jesse,


You can do something with Advanced SQL for this using an input with Expand Inline = True. Something like this:



In this case, you can pass the attribute of the table user and it will be the output of your query. Be careful with the output structure, you want to have a Text since it can have dates or numbers if you decide to choose attributes with different types.


This is kind of an advanced scenario, so I would first try to understand what is the added value for such an approach.


Hope it helps.


Cheers,
João

Hi Jesse,

Please share your oml .

Thanks,

Samiksha

Rank: #70
Solution

Hi Jesse,


You can do something with Advanced SQL for this using an input with Expand Inline = True. Something like this:



In this case, you can pass the attribute of the table user and it will be the output of your query. Be careful with the output structure, you want to have a Text since it can have dates or numbers if you decide to choose attributes with different types.


This is kind of an advanced scenario, so I would first try to understand what is the added value for such an approach.


Hope it helps.


Cheers,
João

Rank: #172

Hi Jesse,

I created a possible solution that maybe can help you.

Look the example in attachment.

Best Regards.

Example.oml

Rank: #495

Hi Jesse, 

Unfortunately, I think it's not possible in outsystems?

Just curious why you need access attribute by name?

Hi! 

Perhaps you can build a function for that, using a SQL using a "expand inline" parameter, but it would be raising a warning message as this parameter will be consider unsafe. 

 

This could be the base SQL, but it is not safe , and I  discourage you to use it. 

Hope you find other solution

Graça