Tuesday, 2 December 2014

Method to get the barcode in AX 2012

Method to get the barcode
private ItemBarCode getBarcodeString(ItemId _itemId, InventDimId _inventDimId)
{
    ItemBarCode     barCodeString;
    BarcodeSetupId  barcodeSetupId  = InventParameters::find().BarcodeSetupIdPick;
    ;

    barCodeString     = InventItemBarcode::findByProductDimensions(_itemId,
                            InventDim::find(_inventDimId),
                                false,false,barcodeSetupId,false).itemBarCode;

    return barCodeString;
}

Method to get the encoded barcode string
private BarCodeString getEncodedBarCodeString(ItemId _itemId, InventDimId _inventDimId)
{
    BarCodeString   EncodedBarCodeString;
    BarcodeSetupId  barcodeSetupId  = InventParameters::find().BarcodeSetupIdPick;
    BarcodeSetup    barcodeSetup    = BarcodeSetup::find(barcodeSetupId);
    Barcode         barcode         = barcodeSetup.barcode();
    ItemBarCode     itemBarCode;
    ;
    itemBarCode = this.getBarcodeString(_itemId, _inventDimId);

    if (barcodeSetup.validateBarcode(itemBarCode))
    {
        barcode.string(true, itemBarCode);
        barcode.encode();
    }
    else
    {
        throw(error(strfmt("@SYS41409", barcode.barcodeType(), itemBarCode)));
    }

    EncodedBarCodeString = barcode.barcodeStr();
    return EncodedBarCodeString;
}

No comments:

Post a Comment

Best Practices for Troubleshooting Application Issues in D365 and Power Platform

When facing application issues, it’s important to systematically troubleshoot before reaching out for support.  Follow these steps to ensure...