Announcements
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
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:
"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.
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.
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
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))
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.
André Arnaud de Cal...
294,000
Super User 2025 Season 1
Martin Dráb
232,850
Most Valuable Professional
nmaenpaa
101,158
Moderator