Thursday, 5 April 2018

Form Data source Modified field in D365


public static class InventTransferOrders_Extension
{

    /// <summary>
    /// Assign Barcode based on Item Id
    /// </summary>
    /// <param name="sender">
    /// </param>
    /// <param name="e">
    /// </param>
    
    [FormDataFieldEventHandler(formDataFieldStr(InventTransferOrders, InventTransferLine, ItemId), FormDataFieldEventType::Modified)]
    public static void ItemId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        FormDataSource          inventTransferLine_ds   = sender.datasource();
        InventTransferLine      inventTransferLine      = inventTransferLine_ds.cursor();
        InventDim               inventDim;
        InventItemBarcode       inventItemBarcode;

        inventDim           = InventDim::find(inventTransferLine.InventDimId);
        inventItemBarcode   = InventItemBarcode::findPurchBarcodeDimension(inventTransferLine.ItemId, inventDim, '', InventTableModule::find(inventTransferLine.ItemId, ModuleInventPurchSales::Invent).UnitId);

        if (!inventItemBarcode.RecId)
        {
            inventItemBarcode = InventItemBarcode::findPurchBarcodeDimension(inventTransferLine.ItemId, inventDim);
        }
        inventTransferLine.BarCode = inventItemBarcode.ItemBarCode;  //custom field
    }

}

No comments:

Post a Comment