I have to perform certain business logic based on the value of a field on a table.
Table1.FIeld1 we will call it. Field1 is a RefRecId in reference to:
Table2.RecId.
On the form that Table1 is a datasource for it shows as Table2.Name.
The table and field can be dynamic but I need to be able to:
Look at Table1.Field1 and find what table the recId is referencing.
FInd the record in Table2 based on that recId and some how get to the Table2.name value. I believe this is set up through the replacement key index.
Is there a way to do this through X++ code? I've been playing around with dictRelation, dictField class but not seeing any methods that get me anywhere.
Thanks
*This post is locked for comments
Thank you @Diluted. I was looking for the same solution my case and it helped me too.
Also maybe someone looks for enum values. Id like to add that too.
public static str getEnumValue(EnumId _enumId, int _enumValue)
{
DictEnum dictEnum;
str ret;
dictEnum = new DictEnum(_enumId);
ret = dictEnum.value2Name(_enumValue);
return ret;
}
private str getRecIdValue(TableId _tableId, FieldId _fieldId, RefRecId _refRecId) { DictTable dictTable; DictRelation dictRelation; DictIndex dictIndex; TableId relTable; FieldId relField; Common common; str ret; dictRelation = new DictRelation(_tableId); dictRelation.loadFieldRelation(_fieldId); relTable = dictRelation.externTable(); dictTable = new DictTable(relTable); common = dictTable.makeRecord(); select common where common.recId == _refRecId; dictIndex = new dictIndex(relTable, dictTable.replacementKey()); relField = dictIndex.field(1); //Replacement key should only have 1 value ret = common.(relField); return ret; }
The above code I wrote resolved my issue and allowed me to grab the value of the replacement key to the related table based on the RecId I am given from the user.
I will update as I find more but by using dictRelation to get the related table through load FieldRelation, I can use dictTable to get the replacement key index through the replacementKey method. I think this will allow me to get the field by just grabbing the first field from the index through dictIndex.Field.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156