Search code examples
sqlaxaptax++dynamics-ax-2012morph-x

Detect whether the connection exists between fields in Dynamics-AX-2012


I have two tables, table1(fields: playerId, insuranceId) and table2.

How to determine from table2 if the playerId and insuranceId have a connection to each other?

I mean which player have agreement with which insurance company...

I know that I should override method(which one?) in table to and use table1 exist method to make it work, but I don't know how to do it.


Solution

  • I don't sure I understand you correctly, but you create next method on table2

    public boolean existInTable1()
    {
        table1 t;
        ;
        select recid from t where t.playerid == this.playerid && t.insuranceid == this.insuranceid;
    
        return (t.recid !== 0);
    }
    

    And somewhere in code:

    table2 t2;
    ;
    select t2;
    if(t2.existInTable1()) ...
    

    Updated

    Of course, if you have exist-method on table1 you can rewrite existInTable1() like this:

    public boolean existInTable1()
    {
        ;
        return table1::exist(this.playerid, this.insuranceid);
    }