OK, I've no idea how this can be going wrong. It seems like Dynamics is deliberately disobeying my my code.
Here is the relevant part.
if (element.args().dataset() == tablenum(ProjectLine))
{
this.query().dataSourceTable(tablenum(ProjectCustomerQuotation)).clearDynalinks();
queryDataSourceLink = this.query().dataSourceTable(tablenum(ProjectCustomerQuotation)).addDataSource(tablenum(ProjectLine));
queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,ProjectId),element.args().record(),fieldnum(ProjectLine, ProjectId));
queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,CustAccount),element.args().record(),fieldnum(ProjectLine, CustAccount));
}
When the query runs the Dynalinks created are on ProjectLine.ProjectId == ProjectLine.ProjectId and ProjectLine.CustAccount == ProjectLine.CustAccount
Which is obviously useless.
I threw a breakpoint on the second addDynalink command and took a look at the value of the queryDataSourceLink and saw this:
SELECT * FROM ProjectLine WHERE ProjectLine.ProjectId=ProjectLine.ProjectId
Any idea why/how Dynamics can ignore the part in bold where I specify a totally different Table?
queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,ProjectId),element.args().record(),fieldnum(ProjectLine, ProjectId));