Set TableRelation with C/AL

I have a quite of a problem. I am trying to design a page for NAV 2009 RTC, and I want to use the dropdown-feature.

Unfortunately, you only can set the source, what will be displayed in the dropdown, only if you configure the TableRelation.

The problem: The TableRelation is dynamic.

My current setup. I have two new tables. Attributes and ItemAttributes. The Attributes table has (besides other) a CODE and an OPTION (Text, File, Measure, List, Number, Url, YesNo, Item…)

I have created a sub-part list with lines for the Retail Item page (Item Attributes Sub). There are two fields on the sub page, “Attr. Code” and Value. Now there’s the tricky part. I want to use the dropdown feature on the Value field, while the user is typing and he see the suggetions. The problem, i can not resolute by now, If the user has defines “Attr. Code”, navision has to look up the Attributes table and the get the OPTION. If the option is (for example) List, it has the set the TableRelation to the table AttributeAllowedValues with a filter “Attr. Code”. If the OPTION is e.g. Item, it has to set the TableRelation to the Item table (with no filter). If the OPTION is Text, it has to lookup and check some other values from the Attributes table and then decide wether the TableRealtion is Table X with filter, Table Y with no filter or no TableRelation (no user assistance).

Which trigger do I have to edit, and how can i reset the TableRelation by C/AL

hi Daniel,

You can look at T37 No. Table relation as an example that is somewhat flexible or you can write C/AL code for the onlookup trigger .


Yes, I looked up Table 37. I have seen the TableRelation settings with the CONST values. However, my problem ist, that i have to generate the settings by C/AL code dynamically on runtime, so I can not use the TableRelation wizzard. On the other hand, if I am writing in the OnLookup-trigger, the dropdown feature will be disabled and then i can only use a popup (Lookup) window. I already done my functions I want with the popup windows solution, but I don’t want a popup. I want to achieve the same with the dropdown-feature :slight_smile:

I kind of managed it, but not all of it. I created a flow field on the ItemAttributes called AttributeTypeFlow its an option. I used this calcformular Lookup(Attributes.Type WHERE (Code=FIELD(Attr. Code))).

Then i created a conditional TableRelation on my Value field in the Sub-Part Page. However, this works well, but only if AttributeTypeFlow is zero. I guess i somehow need to do a calcfields on AttributeTypeFlow, buw how? I can not use OnAfterGetRecord, because i need delayed insert. Can I somewhere set a property to force calcfields before testing the condition?

Yes, i got it to work. I inserted Rec.CALCFIELDS on every trigger ( :slight_smile: ) OnInsert, OneNew, OnControlAddin, OnAfterGetRecord, “Attr. Code OnValidate” and so on