44
Views
14
Comments
Solved
Retrieve name of list attribute
Question

Hi

I was wondering if it is possible to retrieve the name of a List-attribute. 

F.i. A list has 10 attributes :  AT1, AT2, AT3 .. AT10

Depending on the  name of the attribute i want to ùse a Link to go to a following Webpage using the name as an input Variable. In that page i take actions depending on the received value. i dont want to use the attributename as a hardcoded value.

I hope you understand my question.

Thanks in advance


Huub Keulartz 

 


mvp_badge
MVP
Rank: #5
Solution

Yes. Dorine is right. The biggest advantage of not having multiple columns for "weeks" is that if in the future the number of weeks change, you don't have problems with that. Fixing a number of columns for something that may vary is not uncommon, as it may make some things easier on the code side, but was always a bad data pattern...

What you will have to do in terms of presenting is:
a) Transpose the data into a structure (bad, same problem as fixing the columns)

b) Use a list inside a list (better, but may pose a problem depending on the number of access to the database, but there are ways to cope with it)

Cheers  

Hello Huub,

You can use an input variable on the destination page that will ask for the Name of the attribute (as you already said). Thus when you add a link Service Studio will ask you which is the name that you want to pass to input variable of the destination. 

Then on the destination you can make all the actions you want using the input parameter.

If your list has an ID my advice is to work with it, instead of name.

I hope I made my self clear. 

Any doubts just ask :)

Rank: #19455

HI Clarisse

Thank you for your speedy answer! 

But i guess you are talking about the content.  I mean the name of the attribute. 

if the attribute  is AT1 , then i want to pass 'AT1' as a parameter, if i click on the AT2 attribute in the list , want to pass 'AT2' and so on. 

 Huub

mvp_badge
MVP
Rank: #5

Hello Huub,

It may help if you can explain what's the source of this "List"?

Because in OutSystems, any List data type must be known at "design time", meaning, like Clarisse pointed out, that the "name" of the List attribute is known by you at design time, allowing you, for example, to hard coded the name in the link's input parameter.

Cheers.

Rank: #19455

Thanks Eduardo,

But that is just what i DONT want to do: hardcode it. 

the source is a table with a planning for a year for an employee:

 

When i click on week 5 (WK5) i want to go to the detailpage with using 'WK5' as an input parameter. When i click on Week 12 (WK12) i want to use 'WK12" as input parameter. So it s not about teh content but about the name.

I dont know if this is even possible. 

 Huub

Rank: #136

Hi Huub,


I think the root of your problem might be that you have modelled the weeks as attributes of the plan instead of as entities with a relationship to the planyear.  So for each week you only have one attribute, what do you store in it ?  What is the data type ?  Can you tell something more of your user story ?


Dorine


Edit : also, TeamID and EmployeeId are not reference attributes, is that intentional ?

Rank: #19455

HI Dorine

Thank you for your reply. 

yes that was the solution i thought of too, but it is an existing table. I think it will indeed be better to define the week as an attribute.


Huub

mvp_badge
MVP
Rank: #5

Hello Huub.

Directly from OutSystems is not possible to get the name of the attribute. 

If you are looking for the DATABASE name, you may query the metadata entities from System.

In the Entity entity you find the ID of your entity (you need to know its name and the Espace Identifier).
Than, with this Identifier, you can query the Entity_Attr entity, that will have the name of the attributes in the database.

But if you are not behind the database names, well, as you need to know the name of the attribute already, that kind of miss the point here, I think... 

You may be able to do what you want (possibly) with an extension (never did, but remember someone looking for that as well, some time ago), but I think the level of work is to high, when you already know the names of the attributes, and simply hardcoding it would give much less trouble, as this is something that "shouldn't" change .

Why don't you want to hard code? Because its a lot of attributes? Or because you may change the name of the attributes in the future, and don't want to have to keep track of code using them?

Cheers.

Rank: #19455

Hi Eduardo


I will look into that, but i am also considering a redesign of the table. But that will give me some new challenges presenting it. But i will try.

Thanks

 

mvp_badge
MVP
Rank: #5
Solution

Yes. Dorine is right. The biggest advantage of not having multiple columns for "weeks" is that if in the future the number of weeks change, you don't have problems with that. Fixing a number of columns for something that may vary is not uncommon, as it may make some things easier on the code side, but was always a bad data pattern...

What you will have to do in terms of presenting is:
a) Transpose the data into a structure (bad, same problem as fixing the columns)

b) Use a list inside a list (better, but may pose a problem depending on the number of access to the database, but there are ways to cope with it)

Cheers  

Rank: #19455

Thank you all !!

Back to the drawing board!

Rank: #136

Hi all,


this problem got me curious as to how do it with sticking to this data model and at the same time not having to hardcode 52 weeks somewhere in your code.

So I came up with this (I guess that falls into category a, Eduardo ?)

use jsonserialise followed by some text manipulation to turn the entity variable into a list of label and value.  see attached oml.

Eduardo, out of curiosity, what do you mean with option b ?


Dorine

DemoSoftAttributeName.oml

mvp_badge
MVP
Rank: #5

Hi Dorine,

I was referring to solutions to show the data in the interface, when you change the data model and starts having an extra entity with the weeks (one record per week, for example), instead of having them fixed in the main entity.

Eduardo