web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ Possible to get table relationship, then identify the ReplacementKey field to perform logic

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    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.

  • Verified answer
    Community Member Profile Picture
    on at
    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.

  • Community Member Profile Picture
    on at

    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;

       }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#1
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#1
Pratik Bhosle Profile Picture

Pratik Bhosle 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans