Find related field in Dynamics AX
        Posted  
        
            by DAXShekhar
        on Geeks with Blogs
        
        See other posts from Geeks with Blogs
        
            or by DAXShekhar
        
        
        
        Published on Sat, 03 Apr 2010 16:59:21 GMT
        Indexed on 
            2010/04/03
            18:13 UTC
        
        
        Read the original article
        Hit count: 415
        
{
SysDictTable dictTable = new SysDictTable(tablenum(InventTrans));
int i,j;
SysDictRelation dictRelation;
TableId externId = tablenum(SalesLine);
IndexId indexId;
;
// Search the explicit relations     
    for (i = 1; i <= dictTable.relationCnt(); ++i)      
    {      
        dictRelation = new SysDictRelation(dictTable.id());      
        dictRelation.loadNameRelation(dictTable.relation(i)); 
// If it is a 'relation' then you use externTable(), but for extended data types you use table() (see next block).     
        if (SysDictRelation::externId(dictRelation) == externId)      
        {      
            for (j =1; j <= dictRelation.lines(); j++)      
            {      
                info(strfmt("%1", dictRelation.lineExternTableValue(j)));      
                info(fieldid2name(dictRelation.externTable(),dictRelation.lineExternTableValue(j)));      
            }      
        }      
    } 
    info(strfmt("%1", dictRelation.loadFieldRelation(fieldnum(InventTrans, InventTransId))));     
}
© Geeks with Blogs or respective owner