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

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...