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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Can I use x++ code to change the parent datasource for an existing query which created in X++?

(0) ShareShare
ReportReport
Posted on by

Lets say I use X++ code created a query that includes two datasource and the joinMode is NoExistsJoin. (select A that not exists in B)

can I use X++ code to change B to be the parent datasource for the query? (which means I want select B that not exists in A)

---------------------

And here is the real scenario which is more complicated than above, and why I don't want to create a new query from scratch.

I have a table that saves the packed query string (and the query may contain some joined datasource), then I will unpack the query string to get the query object. And now I have another datasource X. I want to noexistsjoin X with the first datasource in packed query (while still keep the other joined datasource in the packed query). Because I don't want to rewrite all the join and links in the packed query.

Thanks,

Jim

*This post is locked for comments

I have the same question (0)
  • Jie G Profile Picture
    Microsoft Employee on at

    Hi Jim, 

    Why not create a new query?

  • Mea_ Profile Picture
    60,286 on at

    Hi Jim Chi,

    It's easier to create 2 queries instead of trying to swap datasources.

  • Community Member Profile Picture
    on at

    Actually the real scenario is more complicated than the post.

    I have a table that saves the packed query string (and the query may contain some joined datasource), then I will unpack the query string to get the query object. And now I have another datasource X. I want to noexistsjoin X with the first datasource in packed query (while still keep the other joined datasource in the packed query). Because I don't want to rewrite all the join and links in the packed query.

  • Mea_ Profile Picture
    60,286 on at

    I don't know any easy way to add new root datasource to existing query, however, you can create new query, put X as a root datasource and then iterate through all datasources in saved query and add them one by one with all relations and ranges to new query.

  • Rustem Galiamov Profile Picture
    8,072 on at

    Hi Jim,

    Try to use UnionType in a query.

    For example :

       QueryBuildDataSource    qbds_1, qbds_2, qbds_3;

       QueryBuildRange           qbr_1, qbr_2, qbr_3;

       super();

       this.query().queryType(QueryType::Union);

       qbds_1 = this.query().dataSourceTable(tableNum(UNC_InventBatchTypes));

       qbds_1.unionType(UnionType::Union);

       qbr_1 = qbds_1.addRange(fieldNum(UNC_InventBatchTypes, Code));

       qbr_1.value("П17300000000100");

       qbr_1 = qbds_1.addRange(fieldNum(UNC_InventBatchTypes, VendAccount));

       qbr_1.value(vendAccount);

       qbds_2 = this.query().addDataSource(tableNum(UNC_InventBatchTypes));

       qbds_2.unionType(UnionType::Union);

       qbds_3 = qbds_2.addDataSource(tableNum(UNC_MaxWinding));

       qbds_3.addLink(fieldNum(UNC_InventBatchTypes, Code), fieldNum(UNC_MaxWinding, TareCode));

       qbds_3.addLink(fieldNum(UNC_InventBatchTypes, VendAccount), fieldNum(UNC_MaxWinding, VendAccount));

       qbr_3 = qbds_3.addRange(fieldNum(UNC_MaxWinding, ItemId));

       qbr_3.value(itemId);

       qbr_3 = qbds_3.addRange(fieldNum(UNC_MaxWinding, VendAccount));

       qbr_3.value(vendAccount);

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 28

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans