Thursday, February 2, 2017

Advance Display method

InventOnHandItem form always a trickier one to customize. A requirement was put by customer to add bar-code number for an item in grid of InventOnHandItem form. Since in AX bar-code on items are assigned on combination of ItemId and InventDim, the trick here is that the InventSum is grouped by InventDim fields. So, your display method will not get an inventdim or inventsum record per se, but a grouped version of those, based on the display settings (the button Dimensions Display which you can find on a lot of forms in AX under the inventory buttons).

So first, since this is to be added as a form datasource display method, and used on a grid, we need the InventSum record passed in as a parameter to the display method. Next, we need to get the dimension field values from the inventdim record to be used in a new join. Since this display method is on the InventSum, we need to get the joined inventDim record, which we can get by calling "joinChild" on the inventSum buffer.

display ItemBarcode getItemBarcode(InventSum _inventSum)
{
    InventItemBarcode       itemBarcode;

    InventDim               inventDimLocal, inventDimJoin;

    // Important part
    inventDimJoin.data(_inventSum.joinChild());
    inventDimLocal.initFromInventDim(inventDimJoin);

    select firstOnly itemBarcode
        where itemBarcode.itemId == _inventSum.ItemId
    join RecId from inventDimLocal
        where itemBarcode.inventDimId == inventDimLocal.inventDimId
           && inventDimLocal.InventSizeId == inventDimLocal.InventSizeId
           && inventDimLocal.InventColorId == inventDimLocal.InventColorId;

    return itemBarcode.ItemBarcode;

 }

Output


3 comments: