Thursday, August 11, 2016

Auto Generate Item Barcode in ax 2012

//Auto Generate Barcode in ax 2012
public static void main(Args _args)
{
    InventItemBarcode   barcode, argBarcode;
    InventDim           inventDim, barcodeInventDim;
    EcoResDistinctProductVariant EcoResDistinctProductVariant;
    InventDimCombination InventDimCombination, comb;
    InventTable inventTable;
    str itemBarcode;

    InventTable = _args.record();

    while select EcoResDistinctProductVariant where EcoResDistinctProductVariant.ProductMaster == InventTable.product
        join InventDimCombination where InventDimCombination.DistinctProductVariant == EcoResDistinctProductVariant.RecId
            join inventDim where inventDim.inventDimId == InventDimCombination.InventDimId
    {

        itemBarcode = "";
        if (InventDimCombination)
        {
            barcodeInventDim.clear();
            barcodeInventDim.InventSizeId = InventDimCombination.inventDim().InventSizeId;
            barcodeInventDim.InventColorId = InventDimCombination.inventDim().InventColorId;
            barcodeInventDim.InventStyleId = InventDimCombination.inventDim().InventStyleId;
            barcodeInventDim.configId = InventDimCombination.inventDim().ConfigId;
            barcodeInventDim = inventDim::findOrCreate(barcodeInventDim);
            barcode.clear();
            barcode.initValue();
            barcode.itemId = InventTable.ItemId;
            barcode.initFromItemId();
            barcode.RetailVariantId = InventDimCombination.RetailVariantId;
            barcode.inventDimId = barcodeInventDim.inventDimId;
            barcode.barcodeSetupId = EcoResProductParameters::find().Fcc_BarcodeSetupId;
            barcode.useForInput = NoYes::Yes;
            barcode.useForPrinting = NoYes::Yes;
            barcode.description = InventDimCombination.defaultProductName();
            if(barcodeInventDim.InventSizeId != "" && barcodeInventDim.InventColorId != "")
            {
                itemBarcode = strFmt("%1-%2-%3",inventTable.ItemId,barcodeInventDim.InventSizeId, barcodeInventDim.InventColorId);
            }
            else
                if (barcodeInventDim.InventSizeId != "" && barcodeInventDim.InventColorId == "")
                {
                    itemBarcode = strFmt("%1-%2",inventTable.ItemId,barcodeInventDim.InventSizeId);
                }
            else
                if (barcodeInventDim.InventSizeId == "" && barcodeInventDim.InventColorId != "")
                {
                     itemBarcode = strFmt("%1-%2",inventTable.ItemId,barcodeInventDim.InventColorId);
                }
            barcode.itemBarCode = itemBarcode;
            if (barcode.validateWrite())
            barcode.insert();
        }
    }

}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...