Problem with add datasource on form - outerjoin

Hi,

I would like add datasource (table name MyTable) to the form InventTransferJour and show data from MyTable on grid. I added table, set on MyTable joinSource - InventTransferJour - and LinkType - Outer Join- .

I have to add relation in method MyTable.init() - so there should be relation through InventTransferJour.VoucherId = MyTable.VoucherId.

How should I do it please ? How should the code look like ?

AX 2012 R2

Hi Richard

I suggest you to manage the relation on Table side to avoid any customization.

However, you can add this code on Init method of InventTransferJour Table.

public void init()
{
QueryBuildDataSource queryBuildDataSource;

super();

queryBuildDataSource = InventTransferJour_ds.query().dataSourceName(identifierstr(InventTransferJour));

queryBuildDataSource.addLink(fieldnum(MyTable, VoucherId),fieldnum(InventTransferJour, VoucherId));

}

Regards

Thank you for reply. Unfortunatelly Your solution doesn’t work. The error message appears that datasource is not join with (parent) datasource.

Nobody knows please? :frowning:

Can you show us your code and how you’ve configured your data sources?

In MyTable are three rows that should be join to InventTransferJour. But data in grid are triple times if I have this:

On datasource MyTable: Join source InventTrasferJour, LinkType - OuterJoin

My code is now:

MyTable.init()

{

super();

MyTable_ds.queryBuildDataSource().relations(false);
MyTable_ds.queryBuildDataSource().addLink(fieldNum(InventTransferJour, VoucherId), fieldNum(MyTable, VoucherId));

}

I forgot…I added new tabpage where is grid with datasource MyTable

You said: “but data in grid are triple times”. But isn’t it a correct result of your join? I don’t know your data, but the most probable explanation is that the code does exactly what you told him to do, regardless that you maybe wanted something else.

I think you’re right. So could you help me with this please?

In the table InventTransferJour are rows with VoucherId:

VC1

VC2

VC3

Now in the table MyTable are three rows with VoucherId:

VC2, some other values

VC2, some other values

VC2, some other values

I would like to do parent/child. So I created new Tabpage on form (InventTransferJour) with grid where should be show data from MyTable. Between InvoiceTransferJour and MyTable doesn’t exist relation on the tables and I have to create relation on the form only.

How should I do it please?

Do you have any reason not to use the usual delayed link instead of a join?

No. But I changed outerjoin to delayed and I added code to MyTable.init() method () as I wrote previous post, the error message shows:
The data source is not embedded within a (parent) data source.

Links and joins are very different things. If you switch from a join to a delayed link, you can’t use addLink(), because the data source are not in the same query anymore.

But you can use a dynamic link between independent data sources. In your case, the implementation would look something like this:

this.queryBuildDataSource()
        .addDynalink(fieldNum(MyTable, VoucherId),
                     inventTransJour,
                     fieldNum(InventTransJour, VoucherId));

Or if you can define a relation, you may be able to avoid all these troubles.

Many thanks, Martin. Your solution is correct.