Skip to main content



No record found.

Microsoft Dynamics AX forum

Creating Financial Dimensions through X++ Code

Posted on by 5

Hello guys,

So i've been asked to write an X code which imports Financial Dimensions (Dimension Attribute) and their values (DimensionFinancialTag) from an Excel file, the code i wrote successfully adds values to an existing Fianacial Dimension (created manually via the form) but if the Financial Dimension does not exist it has to create a new one, which it did apparently, but it couldnt somehow add values to this newly created FinancialDimension. I concluded that my code isnt creating it right. I couldnt find any solution, I tried debugging the whole process but it was too complicated. This is the code I wrote, hopefully someone could find my mistake or could recommend an existing method (Standard) that rightly creates a Financial Dimension.
Thank you guys so much.

static void HMCImportDimensionsFinancieres(Args _args)
    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    COMVariantType          type;

    int                     row=1;
    Dialog                  dialog;
    DialogField             dialogField;
    Filename                filename;

    DimensionAttribute              _dimensionAttribute;
    DimensionFinancialTag           _dimensionFinancialTag;
    DimensionAttributeDirCategory   _dimensionAttributeDirCategory;
    DimensionValue                  _dimensionValue;
    Description                     _description;
    Name                            _name;
    RecId                           _financialTagGategoryRecId;
    int                             nb_dim,nb_val;

    application =           SysExcelApplication::construct();
    workbooks =             application.workbooks();
    dialog =                new Dialog("FileOpen");
    dialogField =           dialog.addField(extendedTypeStr(FilenameOpen),"File Name");;

    if (
        filename =          dialogField.value();
    catch (Exception::Error)
        throw error("File Cannot Be Found");

    workbook =              workbooks.item(1);
    worksheets =            workbook.worksheets();
    worksheet =             worksheets.itemFromNum(1);
    cells =                 worksheet.cells();



        row  ;
        _name           = cells.item(row, 1).value().bStr();
        _dimensionValue = num2str(cells.item(row, 3).value().double(),0,0,0,0);
        _description    = cells.item(row, 4).value().bStr();

        _dimensionAttribute = DimensionAttribute::findByName(_name);
            _dimensionAttribute.Name = _name;
            _dimensionAttribute.BackingEntityType = tableNum(DimensionFinancialTag);
            _dimensionAttribute.ViewName = 'DimensionFinancialTag' ;
            nb_dim   ;
        _dimensionAttribute         =   DimensionAttribute::findByName(_name);
        _financialTagGategoryRecId  =   _dimensionAttribute.financialTagCategory();
        _dimensionFinancialTag      =   DimensionFinancialTag::findByFinancialTagCategoryAndValue(_financialTagGategoryRecId,_dimensionValue,true);

            _dimensionFinancialTag.Description          =   _description;
            _dimensionFinancialTag.Value                =   _dimensionValue;
            _dimensionFinancialTag.FinancialTagCategory =   _financialTagGategoryRecId;
                nb_val    ;


        type = cells.item(row 1, 1).value().variantType();

    while (type != COMVariantType::VT_EMPTY);
    info(strFmt('%1 dimensions ont été importées',nb_dim));
    info(strFmt('%1 valeurs de dimension ont été importées',nb_val));

  • Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Creating Financial Dimensions through X++ Code

    Good to here, please mark answer(s) that helped you as verified to close this thread.

  • Verified answer
    RE: Creating Financial Dimensions through X++ Code

    Hey ievgen Miroshnikov, I really want to thank you for your interaction with me, I found the solution, the problem was that after creating a DimensionAttribute, I didnt create a FinancialTagCategory and a DimensionAttributeDirCategory (while in standard the system creates them automatically), so i inserted one record each and it worked. here's what i did:

    _dimensionAttribute = DimensionAttribute::findByName(_name);



               _dimensionAttribute.Name = _name;

               _dimensionAttribute.BackingEntityType = tableNum(DimensionFinancialTag);

               _dimensionAttribute.ViewName = 'DimensionFinancialTag' ;

               _dimensionAttribute.BackingEntityTableName = 'DimensionFinancialTag' ;


               _financialTagCategory.Mask = ' ';


               _dimensionAttributeDirCategory.DimensionAttribute = _dimensionAttribute.RecId;

               _dimensionAttributeDirCategory.DirCategory = _financialTagCategory.RecId;



  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Creating Financial Dimensions through X++ Code

    Here is an example how to create FinancialCategoryTag but you need to know where to get a value for it

  • RE: Creating Financial Dimensions through X++ Code

    Hey, thanks for the reply, I just realized this "&& _financialTagGategoryRecId" was unnecessary, the problem is i cant add Values with an empty FianacialCategoryTag, so in the process of creating a New DimensionAttribute I need to create with it a FianacialCategoryTag. This i couldnt do. Importing values works perfectly, on the other hand DimensionAttributes aren't created correctly.

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Creating Financial Dimensions through X++ Code

    First of all, here is a blog post that does something similar

    Secondly, what do you want to do here ?


    This line is "true" only if you don't have _financialTagGategoryRecId value, so why do you create a record in _dimensionFinancialTag with empty category ? Maybe you wanted to write 

    if(!_dimensionFinancialTag && _financialTagGategoryRecId)

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,995 Super User

Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans