Lookup on EcoResProductAttributeValue and EcoResTextValue


I am trying to create a lookup in D365FO using the EcoResProductAttributeValue view and EcoResTextValue table. What I want to achieve is a lookup that will receive the lookup control and attribute to look for. The drop down would then display a list of available values for that attribute. The problem I am having is that I don’t seem to be able to make the link between the EcoResProductAttributeValue and EcoResTextValue. I changed the setup code below to show me the value from EcoResAttributeValue, the TextValue from EcoResTextValue and the RecID from EcoResTextValue. When I click the drop down, the Value from EcoResAttributeValue is the correct record id in EcoResTextValue, but the EcoResTextValue fields are not correct. It is like a link doesn’t exist even through I created one. What am I missing in this lookup?


The code for the lookup I have is below.

public static void lookupAttributeGroup(FormStringControl _ctrl, EcoResAttribute _Attribute)
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(EcoResProductAttributeValue), _ctrl);
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildDataSource qbdsJoin;
EcoResAttributeType AttribType;

AttribType = EcoResAttributeType::find(_Attribute.AttributeType);
qbds = query.addDataSource(tablenum(EcoResProductAttributeValue));
qbds.addRange(fieldnum(EcoResProductAttributeValue, Attribute)).value(queryValue(_Attribute.RecId));
switch (AttribType.DataType)
case AttributeDataType::Text : QbdsJoin = query.dataSourceTable(tableNum(EcoResProductAttributeValue)).AddDataSource(tableNum(EcoResTextValue));
QbdsJoin.addLink(fieldNum(EcoResProductAttributeValue, Value), fieldNum(EcoResTextValue, RecId));

sysTableLookup.addLookupField(fieldnum(EcoResProductAttributeValue, Value));
sysTableLookup.addLookupfield(fieldnum(EcoResTextValue, TextValue));
sysTableLookup.addLookupField(fieldnum(EcoResTextValue, Recid));

You have wrong expectations about what addLookupField() does. It accepts a field number, but not a table number, because it always uses the table you used in newParameters() (EcoResProductAttributeValue, in your case).

Therefore your code addLookupField(fieldNum(EcoResTextValue, TextValue)) actually means this: “add the field from EcoResProductAttributeValue table which has the same ID as TextValue field in EcoResProductAttributeValue”.


Thank you for pointing out my mistake. I was tying the lookup field to the query instead of the table assigned to the SysTableLookup. I changed the process to where the SysTableLookup is tied to EcoResTextvalue and I can get the results I was hoping form. Thank you for your help.