Tuesday, November 19, 2019

D365FO Transfer order picking list registration with split quantity

During picking list registration in Transfer order we may need to split the lines for batch number or serial number registration.

below code will be used for split the transaction. (Select line -> Function -> Spilt)

public void split transactions(RefRecId _recId, Qty _qty)
{
            WMSOrderTrans     orderTrans;
             WMSOrderTrans    splitTrans;
             InventDim               inventDim;

          orderTrans                            = WMSOrderTrans::findOrderTrans(_recId,true);
          splitedTrans                          = orderTrans.split(_qty);
          inventDim                             =  orderTrans.inventDim();
          inventDim.inventBatchId     = shipmentDataTmp.InventBatchId;
          inventDim                             = InventDim::findOrCreate(inventDim);

           splitedTrans.selectForUpdate(true);
          splitedTrans.inventDimId    = inventDim.inventDimId;
           if(splitedTrans.validateWrite())
           {
                  splitedTrans.update();
           }
}

Note: findOrderTrans method will not be available in standard table. i have written extension class for WMSOrderTrans table.

[ExtensionOf(tableStr(WMSOrderTrans))]
final class WMSOrderTransExample_Extension
{

 static WMSOrderTrans findOrderTrans(RefRecId _recId, boolean _forupdate = false)
    {
        WMSOrderTrans   orderTrans;

        orderTrans.selectForUpdate(_forupdate);

        select firstonly orderTrans
            where orderTrans.RecId == _recId;

        return orderTrans;
    }
}

No comments:

Post a Comment