web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Creating Financial Dimensions through X++ Code

(0) ShareShare
ReportReport
Posted on by 9

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.

//MAN--27/01/2020
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");
    dialog.run();

    if (dialog.run())
    {
        filename =          dialogField.value();
    }
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File Cannot Be Found");
    }

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

    do
    {

            ttsBegin;

        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);
        if(!_dimensionAttribute)
        {
            _dimensionAttribute.Name = _name;
            _dimensionAttribute.BackingEntityType = tableNum(DimensionFinancialTag);
            _dimensionAttribute.ViewName = 'DimensionFinancialTag' ;
            _dimensionAttribute.insert();
            nb_dim   ;
        }
        _dimensionAttribute         =   DimensionAttribute::findByName(_name);
        _financialTagGategoryRecId  =   _dimensionAttribute.financialTagCategory();
        _dimensionFinancialTag      =   DimensionFinancialTag::findByFinancialTagCategoryAndValue(_financialTagGategoryRecId,_dimensionValue,true);

        if((!_dimensionFinancialTag)&&(!_financialTagGategoryRecId))
        {
            _dimensionFinancialTag.clear();
            _dimensionFinancialTag.Description          =   _description;
            _dimensionFinancialTag.Value                =   _dimensionValue;
            _dimensionFinancialTag.FinancialTagCategory =   _financialTagGategoryRecId;
            if(_dimensionFinancialTag.validateWrite())
            {
                _dimensionFinancialTag.insert();
                nb_val    ;
            }
        }

            ttsCommit;

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

    }
    while (type != COMVariantType::VT_EMPTY);
    application.quit();
    info(strFmt('%1 dimensions ont été importées',nb_dim));
    info(strFmt('%1 valeurs de dimension ont été importées',nb_val));
}
dimension-alger.xlsx

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    First of all, here is a blog post that does something similar nareshdax.blogspot.com/.../importing-dimensionfinancialtag-values.html

    Secondly, what do you want to do here ?

    if((!_dimensionFinancialTag)&&(!_financialTagGategoryRecId))

    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)

  • Mohamed Amine NAIJA Profile Picture
    9 on at

    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
    60,284 on at

    Here is an example how to create FinancialCategoryTag mfmujahidmim.wordpress.com/.../ but you need to know where to get a value for it

  • Verified answer
    Mohamed Amine NAIJA Profile Picture
    9 on at

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

           if(!_dimensionAttribute)

           {

               _dimensionAttribute.Name = _name;

               _dimensionAttribute.BackingEntityType = tableNum(DimensionFinancialTag);

               _dimensionAttribute.ViewName = 'DimensionFinancialTag' ;

               _dimensionAttribute.BackingEntityTableName = 'DimensionFinancialTag' ;

               _dimensionAttribute.insert();

               _financialTagCategory.Mask = ' ';

               _financialTagCategory.insert();

               _dimensionAttributeDirCategory.DimensionAttribute = _dimensionAttribute.RecId;

               _dimensionAttributeDirCategory.DirCategory = _financialTagCategory.RecId;

               _dimensionAttributeDirCategory.insert();

           }

  • Mea_ Profile Picture
    60,284 on at

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans