Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Failed to execute query because no root data source on the form matches the root datasource on the query.

(0) ShareShare
ReportReport
Posted on by 15

Error message: "Failed to execute query because no root data source on the form matches the root data source on the query."

I have this problem when I want to test joining 2 data sources by X code.

My form looks simple, just 2 data sources (SaLesTable, SalesLine) with default properties

2021.03.16-13.51.48.429.png

The code below is from SalesLine:init data source.

public void init()
{
    Query                   q;
    QueryBuildDataSource    qBSalesTable;
    QueryBuildDataSource    qBSalesLine;

    super();
    
    q = new Query();

    qBSalesTable  = q.addDataSource(tablenum(SalesTable));
    qBSalesLine = qBSalesTable.addDataSource(tablenum(SalesLine));
    qBSalesLine.addLink(fieldnum(SalesTable,SalesId),fieldnum(SalesLine,SalesId));
    qBSalesLine.joinMode(JoinMode::InnerJoin);
    qBSalesLine.addRange(fieldnum(SalesTable,SalesId)).value("001*");

    info(q.toString());
    this.query(q);
}

Anyone know why I have such an error?

Infolog:

pastedimage1615901501582v1.png

  • Lukasz3 Profile Picture
    15 on at
    RE: Failed to execute query because no root data source on the form matches the root datasource on the query.

    "I have no idea what you mean by "SalesId appears on the grid regardless of the CustAccount value and value filtering does not work". Your code doesn't do anything with CustAccount, nor it hides SalesId in a grid. Either it's unrelated to this discussion, or - if its relevant - you forgot to tell us some important information. But if your goal is adding a link, these other things sound off-topic to me."

    Yes, this is not relevant information yet. I just wanted to add a bit of background on what the opened form should look like if all went well.

    Thanks for the help. I will test it again and give feedback on how it went.

  • Verified answer
    Martin Dráb Profile Picture
    232,850 Most Valuable Professional on at
    RE: Failed to execute query because no root data source on the form matches the root datasource on the query.

    All right, so you want to add a link. Your goal isn't to build the query from scratch, and therefore your current code doesn't match your requirements.

    To add a link, do the following, for example, init form's init():

    QueryBuildDataSource salesLineQbds = salesLine_ds.queryBuildDataSource();
    
    // Remove the standard link
    salesLineQbds.relations(false);
    
    // Add the same link manually
    salesLineQbds.addLink(fieldNum(SalesTable, SalesId), fieldNum(SalesLine, SalesId));

    Make sure you've set up JoinSource and LinkType of SalesLine data source. LinkType must be a join (e.g. InnerJoin), not a link (such as Delayed).

    Regarding "Here my Query looks like this because I wanted to copy exactly [...", your query is almost correct, but it's set to a wrong data source.

    I'm not sure what it "this code" and I can't comment on the error unless you told us what it says.

    I have no idea what you mean by "SalesId appears on the grid regardless of the CustAccount value and value filtering does not work". Your code doesn't do anything with CustAccount, nor it hides SalesId in a grid. Either it's unrelated to this discussion, or - if its relevant - you forgot to tell us some important information. But if your goal is adding a link, these other things sound off-topic to me.

  • Lukasz3 Profile Picture
    15 on at
    RE: Failed to execute query because no root data source on the form matches the root datasource on the query.

    My goal is to test the use of the "addLink" method on already working data sources, so here I am using SalesTable and SalesLine.

    Later, I want to move the behavior to where I have a data table and want to bind it to another dynamically delivered one that has no relationship to it.

    So my main intention is to bind SalesTable to SalesLine via addLink.

    "One fundamental problem in your code is that you're trying to add a query for SalesTable to SalesLine data source."
    Here my Query looks like this because I wanted to copy exactly what I get after using info(this.query().toString()); when I simply set on the form, in the SalesLine data source: JoinSource "SalesTable" and JoinMode "InnerJoin".

    So what should my query look like to mimic a normal join between dataSources using the AOT build form properties?
    When I put this code in SalesTable init, it returns an error.
    When I switch SalesTable with SalesLine, then then SalesId appears on the grid regardless of the CustAccount value and value filtering does not work

  • Martin Dráb Profile Picture
    232,850 Most Valuable Professional on at
    RE: Failed to execute query because no root data source on the form matches the root datasource on the query.

    Why exactly are you ignoring the query built for you from your form data source and you're creating another one in code?

    If your intention is adding a range, simply modify the existing query instead of building a new one. For example, put this to init() of SalesTable data source:

    this.queryBuildDataSource().addRange(fieldNum(SalesTable, SalesId)).value('001*');

    Just make sure that SalesTable and SalesLine data sources are linked or joined correctly (depending on your needs).

    One fundamental problem in your code is that you're trying to add a query for SalesTable to SalesLine data source.

    You're also using a field number from SalesTable in SalesLine data source, which may mean a completely different field:

    qBSalesLine.addRange(fieldnum(SalesTable,SalesId))

  • Lukasz3 Profile Picture
    15 on at
    RE: Failed to execute query because no root data source on the form matches the root datasource on the query.

    Additional Info:
    When I test it on QueryRun, then everything works fine. Only on Form DataSource init this error occurs when I try to open the form.

    pastedimage1615905843157v1.png

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,000 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,850 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans