Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Modify existing query within a class

Posted on by 2,983
I'm trying to modify an existing query within a class through this custom method:

private void SetQuery() { Query q; QueryBuildDataSource q0; QueryBuildDataSource q1; QueryBuildDataSource q2; QueryBuildDataSource q3; q = chooseLines.query(); q0 = q.dataSourceTable(tableNum(custPackingSlipTrans)); q1 = q0.addDataSource(tableNum(InventTransOrigin)); q1.addLink(fieldNum(custPackingSlipTrans,InventTransId),fieldNum(InventTransOrigin,InventTransId)); q2 = q1.addDataSource(tableNum(InventTrans)); q2.addLink(fieldNum(InventTransOrigin,RecId),fieldNum(InventTrans,InventTransOrigin)); q2.addLink(fieldNum(custPackingSlipTrans,PackingSlipId),fieldNum(InventTrans,PackingSlipId)); q2.addRange(fieldNum(InventTrans, StatusIssue)).value(strFmt('((statusreceipt == 2) || (statusissue == 2))')); chooseLines.query(q); }

However, the query remains as original, my new datasources are not added to it. What am i doing wrong?

The Original query.tostring() is like this:

# Without changes: SELECT WITH FORCE_PLACEHOLDERS FIRSTFAST * FROM SalesTable(SalesTable) ORDER BY SalesLine.SalesId ASC, SalesLine.LineNum ASC WHERE ((SalesStatus>=1 AND SalesStatus<=2)) JOIN FIRSTFAST * FROM SalesLine(SalesLine) ON SalesTable.SalesId = SalesLine.SalesId AND ((Blocked = 0)) OUTER JOIN * FROM CustPackingSlipTrans(CustPackingSlipTrans) ON SalesLine.InventTransId = CustPackingSlipTrans.InventTransId AND ((FullyMatched = 0)) OUTER JOIN * FROM InventDim(InventDim) ON CustPackingSlipTrans.InventDimId = InventDim.inventDimId EXISTS JOIN * FROM CustPackingSlipJour(CustPackingSlipJour_1) WHERE CustPackingSlipTrans.SalesId = CustPackingSlipJour.SalesId AND CustPackingSlipTrans.PackingSlipId = CustPackingSlipJour.PackingSlipId AND CustPackingSlipTrans.DeliveryDate = CustPackingSlipJour.DeliveryDate AND ((DocumentDate = {ts '2018-01-02 00:00:00.000'}))

Actually SalesTable and SalesLine are the parent data sources, but i need my relation at CustPackingSlip level, which is the second child in the query

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Modify existing query within a class

    Maybe you're calling toString() on a wrong query.

    Or maybe the query is all right and the only problem is that toString() doesn't always give exact information. Try query.xml() instead of query.toString().

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,253 Super User 2024 Season 2 on at
    RE: Modify existing query within a class

    Hi Ghetz,

    Did you also updated the CIL (full or incremental)? If not, you might have tested the code on the old version of the software which did not have the adjustments.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans