Monday, July 11, 2022

How to populate data in form with temp table data source using X++ In D365FO

 How to populate data in form with temp table data source using X++ In D365FO.

Here I am using RecordInsertList to insert data in Temp table.

  • I have added temp table in form.
  • In Form init method I am inserting data into temp table.
  • Using linkPhysicalTableInstance I have assigned to temp table buffer to data source.

Form Init method:

[Form]
Public void init()
{
    CustTable  custTable = element.args().record(); 

    MyTempTable.linkPhysicalTableInstance(MyTempTable::getTempTable(custTable)); // add tempTable instance
 
}
[Table method]

Public static MyTemptable getTempTable(CustTable  _custTable)

{
    MYTempTable         myTempTable;
    SalesTable          salesTable;
    RecordInsertList    tempRecordInsertList = new RecordInsertList(tableNum(MYTempTable),
                                                                     true, true, true, 
                                                                     false, true, myTempTable);
    while select salesTable
       where salesTable.CustAccount == _custTable.CustAccount 	
    {
        myTempTable.clear();
        myTempTable.CustAccount = salesTable.CustAccount;
        myTempTable.SalesId     = salesTable.SalesId;

        tempRecordInsertList.add(myTempTable);
    }

    tempRecordInsertList.insertDatabase();

    return myTempTable;
}

If you want to write select / while select statement for temp table follow the below logic. 
    MyTempTable    MyTempTableLoc; 
    MyTempTableLoc.linkPhysicalTableInstance(MyTempTable);// temp table buffer from init method.
    select MyTempTableLoc where 'your condition';
    while select myTempLoc
    {
        // your logic
    }
Keep Daxing!!

No comments:

Post a Comment