Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Monday, August 5, 2013

lookup with joinning 2 tables in Dynamic AX

Implement this code in the lookup() method of the field where you need the lookup to be displayed.

NS: 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();
}

Find methods() / inserting the values from one form where action is taking place is to be reflect in another form in Dynamic AX

Hi,

public void modified()
{
        SMAServiceObjectTable   smaServiceObjectTable;
    SMAServiceOrderTable    smaServiceOrderTable, smaServiceOrderTable1;
    //Tables I used here and smaServiceOrderTable1 will act as datasource that I added
    TableId                 loctableid;
    super();
    loctableid = element.args().record().TableId;
    if (loctableid == tableNum(smaServiceOrderTable))
        smaServiceOrderTable = element.args().record();
    ttsBegin;
    //Updated by Alfasith- This to display in OrderFormTable
    select forUpdate smaServiceOrderTable1 where smaServiceOrderTable1.RecId == smaServiceOrderTable.RecId;
    smaServiceOrderTable1.AssetId = smaServiceObjectTable::find(SMAServiceObjectRelation.ServiceObjectId).AssetId;
    smaServiceOrderTable1.VehicleRegistrationNo  =  AssetTable::find(smaServiceObjectTable::find(SMAServiceObjectRelation.ServiceObjectId).AssetId).SerialNum;//SMAServiceObjectTable::find(SMAServiceObjectRelation.ServiceObjectId).vehicleRegistrationNo();
    smaServiceOrderTable1.VehicleType  = SMAServiceObjectTable::find(SMAServiceObjectRelation.ServiceObjectId).vehicleType();
    smaServiceOrderTable1.Make  = AssetTable::findByServiceObjectId(SMAServiceObjectRelation.ServiceObjectId).Make;
    smaServiceOrderTable1.NQ_ServiceCentreCode  = smaServiceObjectTable::find(SMAServiceObjectRelation.ServiceObjectId).serviceCentre();
    smaServiceOrderTable1.update();
    ttsCommit;
}

This above sample makes the sense of adding new fields in the form where two forms are involved and results should reflect in another form

How to invoke and iterate List as Contract methods in AX 2012/ D365

Hi, Public void performContractIterate(ClassContainsListAsContract    _ListCarryClass) { List contractFieldList = new List(Types::Class); ...