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 :
Finance | Project Operations, Human Resources, ...
Unanswered

How to join query datasource to EITHER its sister datasource OR its parent?

(0) ShareShare
ReportReport
Posted on by

I am attempting to join a query datasource to Either its parent OR its sister, but am not getting the desired results.

I overrode the init method of the query and added a range to the subject datasource with a query expression after the super() similar to this:

datasourceRange.value('((whsLoadLine.inventTransId == salesLine.inventTransId) || (whsLoadLine.inventTransId == kitSalesLine.inventTransId))');

SalesLine = Parent DS

    kitSalesLine = Child of SalesLine

    whsLoadLine = Child of SalesLine

The issue is that it is not returning whsLoadLine records for the kitSalesLines.

At this point, my assumption is that this just isn't possible.   I can't make the whsLoadLine a child of the KitSalesLine because it would change the formatting of the XML.  This is an aif document query.

I have the same question (0)
  • Martin Dráb Profile Picture
    239,452 Most Valuable Professional on at

    You're skipping an important step in debugging. You write X++ code generating some SQL code and then you check what data is returned by this SQL code. But you don't have any idea whether your X++ code generated the right query and if not, what's wrong with it.

    Also, you're hard-coding data source names in your expressions, but are you sure they're correct? Maybe they're named something like whsLoadLine_1. A safer approach is using QueryBuildDataSource.name().

    By the way, have you verified that your code gets executed at all?

  • MuthukumaranAX Profile Picture
    2,903 on at

    can you confirm what join type you have used b/w these data sources?

    thanks 

  • TimothyOtt3 Profile Picture
    on at

    Hi Martin,

    Thanks for the Reply.  I guess there is a fine line between being concise and providing enough details to a question.

    I did debug and check the SQL, which appeared fine to me.  I used each datasource.toString() which showed me the joins for each DB, but I was not able to get the raw sql.  Is there a good method for this? I attempted to use sql profiler, but I could not find this query hitting the DB.

    I did use a query expression with QuiryBuildDataSource.name(), but was just trying to simplify my question by writing it out.

    Yes, the code gets executed.  In fact, it returns the first part of the join, meaning that it does return whsLoadLine records for the Parent (salesLine), but not the sister (kitLines).

    I think the question is simple.  Can you join to both a sister database OR a parent database using a query object?

  • TimothyOtt3 Profile Picture
    on at

    Here is the query and how I attempted to make the join in the init method.  You can see when I test the query that the join is showing in SQL.  I dont have the output here, but it does return loadLine records for the Parent (salesLine) but not for the Sister (kitLine).  Thanks.

    ParentSisterJoin.jpg

  • Martin Dráb Profile Picture
    239,452 Most Valuable Professional on at

    I did use similar conditional joins in query objects. But not it AOT queries used by AIF document services.

    I don't know if I've ever did *exactly* the same thing as yourself, therefore I can't give you a definite answer to whether it is possible without actually trying it.

    You can catch the actual T-SQL code by either the profiler or extended events.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 622

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 553 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans