Search code examples
axaptax++dynamics-ax-2012

AOT Query relation OR case


For example I have the following x++ query.

Select EcoResproduct
   join tableX
       where EcoResproduct.RecId == tableX.Product
          || EcoResproduct.RecId == tableX.DistinctProductVariant;

Is that possible to do the same thing through AOT query without using a union query or adding two times the same datasource and without using QueryBuildDataSource object and X++ at all .

Thanks in advance

PS: I made my question more clear.


Solution

  • Initial incorrect answer:

    Is that possible to do the same thing through an AOT query without using a union query or adding two times the same datasource

    No.

    Correct answer, thanks to the commenters:

    Query q = new Query();
    QueryBuildDataSource qbds1 = q.addDataSource(tableNum(EcoResproduct));
    QueryBuildDataSource qbds2 = qbds1.addDataSource(tableNum(TableX));
    
    qbds2.addrange(fieldNum(TableX, RecId)).value(strFmt('((%2.Product == %1.RecId) || (%2.DistinctProductVariant == %1.RecId))', qbds1.name(), qbds2.name()));
    
    info(qbds1.toString());