Bài viết liên quan

Macro to insert data in X++ (D365FO)


09/10/2020- duocnt    846 Views    

NGUỒN 

Form InventAgingStorageChart.
Macro: #LOCALMACRO.InsertInventAgingChartTmp.

Ý NGHĨA

 - Mỗi khi method populateQuantity() được gọi, sẽ gọi đến Macro #InsertInventAgingChartTmp và insert dữ      liệu vào InMemory table inventAgingChartTmp.


CODE X++

 - Tạo Macro.

    InventAgingStorage inventAgingStorage;
    InventAgingTmp inventAgingTmp;
    str itemGroupSelTxt, itemSelTxt, siteSelTxt, warehouseSelTxt,filterTxt;
    str txtAll = strFmt('%1', '@SYS11696');
 
   #LOCALMACRO.InsertInventAgingChartTmp
        inventAgingChartTmp.clear();
        inventAgingChartTmp.Period = %1;
        inventAgingChartTmp.TransactionId = inventAgingStorage.TransactionId;
        inventAgingChartTmp.Filters = filterTxt;
 
        select sum(%2) from inventAgingTmp
            where inventAgingTmp.CreatedTransactionId == inventAgingStorage.TransactionId
               && (itemGroupSelTxt == txtAll || inventAgingTmp.ItemGroupId == itemGroupSelTxt)
               && (itemSelTxt == txtAll || inventAgingTmp.ItemId == itemSelTxt)
               && (siteSelTxt == txtAll || inventAgingTmp.InventSiteId == siteSelTxt)
               && (warehouseSelTxt == txtAll || inventAgingTmp.InventLocationId == warehouseSelTxt);
       
        inventAgingChartTmp.PeriodValue = round(inventAgingTmp.%2, 0.01);
        inventAgingChartTmp.insert();
 
        // Add additional zero record to make the chart don't throw error. Each period need at least two records.
        inventAgingChartTmp.clear();
        inventAgingChartTmp.Period = %1;
        inventAgingChartTmp.PeriodValue = 0;
        inventAgingChartTmp.insert();
    #ENDMACRO


 - Gọi Macro.

    private void populateQuantity()
    {
        if (inventAgingStorage)
        {
            delete_from inventAgingChartTmp;
 
            #InsertInventAgingChartTmp(inventAgingStorage.getPeriodText(5), QtyofAgingPeriod5)
            #InsertInventAgingChartTmp(inventAgingStorage.getPeriodText(4), QtyofAgingPeriod4)
            #InsertInventAgingChartTmp(inventAgingStorage.getPeriodText(3), QtyofAgingPeriod3)
            #InsertInventAgingChartTmp(inventAgingStorage.getPeriodText(2), QtyofAgingPeriod2)
            #InsertInventAgingChartTmp(inventAgingStorage.getPeriodText(1), QtyofAgingPeriod1)
 
            InventAgingChartTmp_DS.executeQuery();
        }
    }


Góp ý kiến

;
;