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();
}

3 comments:

  1. Hi ,

    In Excel ItemID value is 00001. When i am trying to import data from excel using above code. i can not get ItemID. Because ItemID value is 00001 and "inventItemBarCode.itemId=itemId" written string value.

    ReplyDelete
  2. You are excellent. Your post is written in great detail.In a word,i'm just new to this filed.I met a lot of problems in my work, there is a lot of very useful knowledge in your post to help me solve problems.I enjoy reading your blog and hope to see more.By the way,Is it possible to generate barcode of an item having batch+serial (tracking dimension) and quantity?
    excel addin for barcode generation

    ReplyDelete
  3. I would really recommend this. It works great for me.
    http://technitya.com/barcode-generator-excel/

    ReplyDelete