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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Find indirect relation from tables

(0) ShareShare
ReportReport
Posted on by 260

Hello guys,

I'm working in a project that require me to find the relation between two random tables

I'm using some sys methods , right now, I can find the direct relation between two tables, but some times the tables have indirect relation which is kind problematic.

I did some google about it, and I didn't find much.

I would like something like this link, but it didn't work well for me
https://lalitoberoi.wordpress.com/2014/08/29/how-to-find-relation-between-two-tables-from-x-code/

Do you guys know any approach for this?



Thanks,

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi bois0155,

    Are these custom tables or standard D365 tables?

  • bois0155 Profile Picture
    260 on at

    The table would be any table in the system, so could be standard or custom I just need to get the relation path between two tables

  • WillWU Profile Picture
    22,363 on at

    Hi bois0155,

    You could use the DictRelation and DictTable classes.

    Please try to loop through all table relations with the following codes.

    static void findRelatedFieldId(TableId _tableIda,TableId _tableIdb)
    
        {
            DictTable    dictTable = new DictTable(_tableIda);
            int             i,j;
            DictRelation dictRelation;
            TableId         externId = _tableIdb;
            IndexId         indexId;
            ;
    
            dictRelation = new DictRelation(dictTable.id());
            // Search relations
            for (i = 1; i <= dictTable.relationCnt(); i  )
            {
                dictRelation.loadNameRelation(dictTable.relation(i));
    
                // If it is a 'relation' then you use externTable(), but for extended data types you use table()
                if ( dictRelation.externTable()== externId)
                {
                    for (j =1; j <= dictRelation.lines(); j  )
                    {
                        info(strfmt("%1", dictRelation.lineExternTableValue(j)));
                        info(fieldid2name(dictRelation.externTable(),dictRelation.lineExternTableValue(j)));
                    }
                }
            }
        }

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Hi bois0155, can you share any details about the underlying business requirement? What would this functionality be used for?

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans