web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Replace/copy query object

(0) ShareShare
ReportReport
Posted on by

Hi,

I want to copy a query object without overwriting the reference. Is there a way to achive this?

There is a method which has a query as parameter. In the method I got a second query. Now I want to overwrite the passed query with the second query so it also changes in the caller method.

query q;

void test(Query _query)

{

Query q2 = new Query();

q2.addDataSource(tableNum(SalesTable));

// ??? here should be the logic that copies the query from q2 to _query

}

q = new Query();

q.addDataSource(tableNum(InventTable));

test(q);

// I want to have q2 available here in object q

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    q3 = new Query(q2);

    // here is short demo job

    static void testQueryCopy(Args _args)

    {

       Query q3 ;

       Query q2 = new Query();

       QueryRun qr;

       SalesTable lclSalesTable;

       q2.addDataSource(tableNum(SalesTable));

       q3 = new Query(q2);

       q3.dataSourceTable(tableNum(SalesTable)).addRange(fieldNum(SalesTable,SalesId)).value(queryValue("000751"));

       qr = new QueryRun(q3);

       while(qr.next())

       {

           lclSalesTable = qr.get(tableNum(SalesTable));

           info(lclSalesTable.SalesId);

       }

    }

  • Community Member Profile Picture
    on at

    This wont work because you overwrite the reference. The essential thing is to have the replaced query available outside in the calling method. If you locally overwrite the reference passed as parameter, you wont change the query object in the caller method.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Why don't you simply let test() return the reference and assign it to q?

    q = test();

  • Community Member Profile Picture
    on at

    I'm trying to overwrite the list page query in the listpage interaction class. The query is passed in the super class which I can't modify

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Well, then be careful to keep in place all data sources that the list page expects. Therefore I wouldn't try to remove the original query, I would merely modify it. You can add data sources (addDataSource()), merge ranges (SysQuery::mergeRanges()) or anything you like.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans