Search This Blog

Wednesday, April 11, 2012

Ax2012 import Dimension financial Tag values from CSV

This job is used to import data into DimensionFinancialTag Table, before doing that first we have to get the record id of financial category that this financialTag values should be inserted.

static void krishh_ImportDimensionFinancialTagValues(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    int row;
    filename  filename;

    str dimvalues;
    str           valuedescr;
    DimensionFinancialTag financialTag;
    RefRecId         categoryRecid;
    ;
    // FinancialCategory Record Recid
    categoryRecid=5637144826;
    filename=@"C:\TEMP\SAP_product_item.xlsx";
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    row=1;

    try
    {
        workbooks.open(filename,0,true);
    }
    catch (Exception::Error)
    {
        throw error("@SYS19358");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();

    //Iterate through cells and get the values
    try
    {
    ttsBegin;
        do
        {
        //Incrementing the row line to next Row
        row++;

        dimvalues = num2str(cells.item(row, 1).value().double(),0,0,0,0);
        valuedescr = num2str(cells.item(row,2).value().double(),0,0,0,0);
        financialTag=DimensionFinancialTag::findByFinancialTagCategoryAndValue(categoryRecid,dimvalues,true);
        if(!financialTag)
        {
            financialTag.clear();
            financialTag.Description=valuedescr;
            financialTag.Value=dimvalues;
            financialTag.FinancialTagCategory=categoryRecid;
            financialTag.insert();
        }
        else
        {
            financialTag.Description=valuedescr;
            financialTag.Value=dimvalues;
            financialTag.FinancialTagCategory=categoryRecid;
            financialTag.skipTTSCheck(true);
            financialTag.update();
        }
        // Loads the next row into the variant type and validating that its is empty or not
        type = cells.item(row+1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);
    ttsCommit;
    }
    catch(Exception::Error)
    {
        ttsAbort;
    }
    // quits the application

    application.DisplayAlerts(false); //dont prompt saving message
    application.quit();
    application = null;
}

3 comments:

  1. hi Krishna,

    I am trying to import financial dimension from an excel sheet. I need your little help I will pay for it. Email me at united5675@yahoo.com

    sid

    ReplyDelete
  2. HI Krishna,
    Do you have solution to import financial dimension?
    Thanks,

    ReplyDelete
  3. Hi

    I have uploaded through the code above mentioned,
    However the data is getting inserted into the table, But data not diplaying in front end.
    can help

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.