23 Feb 2016

lookup with joining two tables in AX 2012

This code in the lookup() method.


The same code can be written in three places to achieve the lookup.
1) Under AOT->Table->Method and cal this method from the form design where you want to display the lookup.
2) Form->Datasource->Table->Field->method
3) Form->Design->Field->Method.

public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildDataSource QbdsJoin;

// Instantiate sysTableLookup object using table which will provide the visible fields
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(TableName), this);
;

// Create the query.
qbds= query.addDataSource(tableNum(TableName));
qbds.addRange(fieldNum(TableName, FieldName)).value('Value');

//Join Table
QbdsJoin= qbds.addDataSource(tableNum(TableName2));
QbdsJoin.relations(true);
QbdsJoin.joinMode(JoinMode::ExistsJoin);
QbdsJoin.addRange(fieldNum(TableName2, Fieldname)).value('Value');

// Set the query to be used by the lookup form
sysTableLookup.parmQuery(query);

// Specify the fields to show in the form.
sysTableLookup.addLookupfield(fieldNum(TableName, FiledName));
sysTableLookup.addLookupfield(fieldId2Ext(fieldNum(TableName, Dimension), 1));

// Perform the lookup
sysTableLookup.performFormLookup();
}

No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...