AddLink on form datasource

Hi,

I have created a form which has AccountingDistribution, PurchTable and PurchLine in datasources, AccountingDistribution will be the primary table, when I try to add a link on PurchTable using addLink in the init method of PurchTable DS, it gives me an error as “The data source is not embedded within a (parent) data source.” The syntax I have used is

PurchTable_ds.query().addDataSource(tableNum(AccountingDistribution));
PurchTable_ds.query().dataSourceTable(tableNum(PurchTable)).joinMode(JoinMode::InnerJoin);
PurchTable_ds.query().dataSourceTable(tableNum(PurchTable)).addLink(fieldNum(PurchTable, SourceDocumentHeader), fieldNum(AccountingDistribution, SourceDocumentHeader));

My purpose is to link

AccountingDistribution and PurchTable on SourceDocumentHeader column and

link AccountingDistribution and PurchLine on SourceDocumentLine column

Could anyone please help me achieve this…

Your help is very much appreciated.

If you already have a data source for AccountingDistribution and it should be the top-level data source, set it to JoinSource of the PurchTable data source. Also set the JoinMode property there, not in code. Your code doesn’t set any data source as a child of the other (as the error message says), therefore you can’t add links between them.

Furthermore, you have to set the parent ID as the first parameter of addLink().

Thanks Martin,

It worked like charm!