Monday, 10 September 2018

Get temp data from class to form Data source AX 2012 + X++

Get temp data from class to form Data source AX 2012 + X++

In the below example we will see how we can use the temporary table as form datasource.
we can use a temporary table as datasource whether it is of type tempDb or InMemory.

1. Create a temporary table and just need to drag into the form datasource.
2. Create a class to fill the temporary table.

public class MK_ItemDiscountGroup
{
    MK_tmpInventTable          tmpInventTable;
   
    PriceDiscGroup              priceDiscGroup;

}
3. add a method to fill temp data and return tempTable

public MK_tmpInventTable fillTmpData()
{
    InventTable         inventTable;
    InventTableModule   inventTableModule;
    //MK_tmpInventTable  tmpInventTable;
    //RecordInsertList insertList = null;
    //insertList = new RecordInsertList(tablenum(MK_tmpInventTable));
    ttsbegin;
    while select inventTable
        join inventTableModule
        where inventTable.ItemId == inventTableModule.ItemId
        && inventTableModule.ModuleType == ModuleInventPurchSales::Sales
        && inventTableModule.LineDisc == priceDiscGroup.GroupId
    {
       
            tmpInventTable.ItemId = inventTable.ItemId;
            tmpInventTable.NameAlias = inventTable.NameAlias;
            tmpInventTable.Name = inventTable::name(inventTable.ItemId);
            tmpInventTable.LineDisc = inventTableModule.LineDisc;
            tmpInventTable.insert();
       
        //insertList.add(tmpInventTable);

    }

    //insertList.insertDatabase();
    ttscommit;
    return tmpInventTable;


}

4. call this method in init method of form after super.

public void init()
{

     super();
     itemDiscountGroup = MK_ItemDiscountGroup::construct(priceDiscGroup);
    itemDiscountGroup.fillTmpData();
    //if table is of type tempDb, call following method.
    MK_tmpInventTable.linkPhysicalTableInstance(itemDiscountGroup.fillTmpData());
    //Note:// if table is of type InMemory,call following method.

    MK_tmpInventTable.setTmpData(element.insertRecords());
}

// important thing comes here
// if the table is of type InMemory, call following method.

TmpTable.setTmpData(element.insertRecords());

// if the table is of type tempDb, call following method.

TmpTable.linkPhysicalTableInstance(element.insertRecords());

No comments:

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...