Import data from Excel for Fixed Asset Location by using previous Fixed Asset template

Import data from Excel for Fixed Asset Location


class FCC_FixedAssetLocationImport
{
    int                 i, j;
}

---------------------

public void readFromExcell()
{
    SysExcelApplication                 application;
    SysExcelWorkbooks                   workbooks;
    SysExcelWorkbook                    workbook;
    SysExcelWorksheets                  worksheets;
    SysExcelWorksheet                   worksheet;
    SysExcelCells                       cells;
    COMVariantType                      type;
    int                                 row =   1;

    Dialog                              dialog;
    DialogField                         dialogPath;
    CommaIO                             inFile;
    FilenameOpen                        fileName;
    //KP
    AssetId                             assetId;
    AssetGroupId                        assetGroupId;
    AssetBookId                         assetBookId;
    AssetLocationId                     location;
    DataAreaId                          dataAreaId;
    AssetTable                          assetTable;
    boolean     ret, error;


    application     =   SysExcelApplication::construct();
    workbooks       =   application.workbooks();


    dialog          =   new Dialog("Import Asset Location");
    dialogPath      =   dialog.addField(extendedTypeStr(Filenameopen), "File Name");
    dialog.run();

    if (dialog.run())
    {
        filename    =   dialogPath.value();
    }

    workbooks.open(filename);

    workbook        =   workbooks.item(1);
    worksheets      =   workbook.worksheets();

    worksheet       =   worksheets.itemFromNum(1);
    cells           =   worksheet.cells();

    do
    {
        row++;
        assetGroupId        = strFmt("%1",cells.item(row,1).value().bStr());
        assetId             = strFmt("%1",cells.item(row,2).value().bStr());
        location            = strFmt("%1",cells.item(row,3).value().bStr());
        dataAreaId          = strFmt("%1",cells.item(row,4).value().bStr());

        select forUpdate assetTable
            where assetTable.AssetId == assetId
                && assetTable.AssetGroup == assetGroupId
                && assetTable.dataAreaId == dataAreaId;

        if(assetTable.Location == "")
        {
            ttsBegin;
            assetTable.Location = location;
            assetTable.update();
            ttsCommit;
        }



        info(strFmt("Default Dimension - %1 ",assetTable.Location));
        type = cells.item(row+1, 1).value().variantType();

}

    while (type != COMVariantType::VT_EMPTY);
    application.quit();


}

---------------------

Public static void main(Args    args)
{
    FCC_FixedAssetLocationImport        fccFixedAssetLocationImport=   new FCC_FixedAssetLocationImport();

    fccFixedAssetLocationImport.readFromExcell();
}

Comments

Popular posts from this blog

Getting Workflow Approvers In Dynamics AX (AX 2012)

To find details individually for ledgerjournaltrans default dimensions

Creating a numbersequence in form level in ax 2012