Showing posts with label Item bar code in AX. Show all posts
Showing posts with label Item bar code in AX. Show all posts

Monday, September 10, 2012

How to update item bar code in ax 2009



static void updateItemBarCode(Args _args)
{
    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    COMVariantType          type;
    int row;
    Str custID,len;
    Name name;
    FileName filename;
    IntrastatItemCodeId     commCode;
    InventItemBarcode  inventItemBarCode;
    InventTable  inventTable;
    Sysdim      dim;
    ItemId      itemId;
    ItemBarCode itemBarCode;
    BarcodeSetupId barcodeSetupId;
    InventDimId inventDimId;
    ;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    //specify the file path that you want to read
    filename ="C:\\New folder (2)\\Barcode2.xlsx";
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    do
    {
       row++;
       itemId=cells.item(row, 1).value().bStr();
   ttsbegin;
    inventTable = InventTable::find(itemId);
    if (inventTable)
    {
        inventItemBarCode.itemBarCode=cells.item(row, 2).value().bStr();
        inventItemBarCode.barcodeSetupId=cells.item(row, 4).value().bStr();
        inventItemBarCode.inventDimId=cells.item(row, 3).value().bStr();
        inventItemBarCode.itemId=itemId;
        inventItemBarCode.insert();
    }
    ttscommit;
    type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    application.quit();
}