Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

building queries

(0) ShareShare
ReportReport
Posted on by

hi,

please am trying to build a query using the code below

static void Job2(Args _args)
{
 Query custTransQuery = new Query();
    QueryBuildDataSource custDataSource;
    QueryBuildDataSource transDataSource;
    QueryBuildDataSource businesstransDataSource;
    QueryBuildDataSource reversalTransDataSource;

    custDataSource = custTransQuery.addDataSource(tableNum(CustTable));
    custDataSource.addOrderByField(fieldNum(CustTable, DataAreaId));
    

    transDataSource = custDataSource.addDataSource(tableNum(CustTrans));

    transDataSource.addLink(fieldNum(CustTable, AccountNum), fieldNum(CustTrans, AccountNum));
    // use outer join because customers without transactions are included
    transDataSource.joinMode(JoinMode::OuterJoin);
    
    transDataSource.addRange(fieldNum(CustTrans, TransType)).value(strFmt('((%1 != %2) && (%1 != %3))',
                                                                            fieldStr(CustTrans, TransType),
                                                                            any2int(LedgerTransType::ExchAdjustment),
                                                                            any2int(LedgerTransType::Settlement)));
    transDataSource.addOrderByField(fieldNum(CustTrans, DataAreaId));
    transDataSource.addOrderByField(fieldNum(CustTrans, TransDate));
    transDataSource.addOrderByField(fieldNum(CustTrans, Voucher));
     businesstransDataSource = transDataSource.addDataSource(tableNum(DefaultDimensionView1));
    businesstransDataSource.joinMode(JoinMode::InnerJoin);
    businesstransDataSource.addLink(fieldNum(CustTrans, defaultdimension), fieldNum(DefaultDimensionView1, defaultdimension));
       reversalTransDataSource = transDataSource.addDataSource(tableNum(TransactionReversalTrans));
        reversalTransDataSource.joinMode(JoinMode::NoExistsJoin);
        reversalTransDataSource.addLink(fieldNum(CustTrans, TableId), fieldNum(TransactionReversalTrans, RefTableId));
        reversalTransDataSource.addLink(fieldNum(CustTrans, RecId), fieldNum(TransactionReversalTrans, RefRecId));
        reversalTransDataSource.addRange(fieldNum(TransactionReversalTrans, Reversed)).value(enum2str(NoYes::Yes));

    info(custTransQuery.dataSourceNo(1).toString());
}

but the results does not include the defaultdimensionview1 table .

i would be grateful if anybody can help me thanks

*This post is locked for comments

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: building queries

    Hi,

    What is it that you want to achieve with your query / adjustment at the end of the day?

    Best regards,

    Ludwig

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,432 Most Valuable Professional on at
    RE: building queries

    Maybe the datasource is used and it's merely not displayed in toString(). Try adding .fetchMode(QueryFetchMode::One2One) to child data sources.

    By the way, please use </> button in the rich formatting view to paste source code; it makes it easier to read. Also, it helps if you simplify your code before sharing it with others, so we don't have to go through a lot of code unrelated to your question.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans