Friday, October 10, 2014

Sample Code for Import new field in ax

\\ Sample Code for Import new field

    SerialNoTrackingPO  serialNoTable;

    SysExcelApplication application;
    SysExcelWorkbooks   workbooks;
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  worksheets;
    SysExcelWorksheet   worksheet;
    SysExcelCells       cells;
    COMVariantType      type;
    int                 row;

    LSPSerialNo  serialNo;
    Dialog              dialog;
    DialogField         dfFileName;
     Filename template;

    PurchId parentPO;
    ;
    super();

    parentPO = PurchId.valueStr();

    #File

    // ttsBegin;
    dialog = new Dialog("Select Excel to Import");

    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));

    dialog.filenameLookupFilter(["All files", #AllFiles]);

    if (dialog.run())
    {
        template = dfFileName.value();
        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        try
        {
            workbooks.open(template);
        }
        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++;
                    serialNoTable.PurchId           = parentPO;//cells.item(row,1).value().bStr();
                    serialNoTable.RetailVariantId   = cells.item(row,1).value().bStr();
                    serialNoTable.LSPSerialNo       = serialNo; //cells.item(row,3).value().bStr();
                    serialNoTable.ShippedQty        = cells.item(row,3).value().double();
                    serialNoTable.insert();
               
        }
        type = cells.item(row+1, 1).value().variantType();

         while (type != COMVariantType::VT_EMPTY);

        application.quit();
    }

  

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...