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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans