Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

DimensionDynamicAccount

Posted on by 543

Hi experts!

I have a field of type DimensionDynamicAccount in AX 2012. It consists of MainAccount, BusinessUnit, Site, CostCentre and Reporting.

When the record is created, I want "Site" to be set to a specific string that I have.

Is it possible to set the "Site" part and not set anything else in the field during insert? If not, can I set the "Site" part when the user enters the field (starting in MainAccount)?

*This post is locked for comments

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: DimensionDynamicAccount

    Hi Adam,

    This works perfectly. You have solved my problem. Thank you very much!

    Best regards,

    Morten

  • Verified answer
    Adam Tarkowski Profile Picture
    Adam Tarkowski 5 on at
    RE: DimensionDynamicAccount

    Hi,

    Sorry guys, there was a missing dimensionStorage.save in the code in my blog post - it is fixed now :).

    Regarding your problem Morten. You should have method below on control which shows ledger dimension. FYI: this is just a draft. Let me know if it works.

    public void segmentValueChanged(SegmentValueChangedEventArgs _e)
    {
        Map dimensionSpecifiers;
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
        str dimValue;

        super(_e);

        dimAccountController.segmentValueChanged(_e);

        if (_e.segment().name() == DimensionAttribute::find(DimensionAttribute::getMainAccountDimensionAttribute()).Name)
        {
            dimensionAttribute = DimensionAttribute::findByName('SITE'); // please do it better ;)
            dimValue = "value of site";
            dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, dimValue);

            dimensionSpecifiers = new Map(Types::Int64, Types::Container);
            dimensionSpecifiers.insert(dimensionAttributeValue.DimensionAttribute, [dimValue, dimensionAttributeValue.RecId, dimensionAttributeValue.HashKey]);

            dimAccountController.setDimensionSpecifierValues(dimensionSpecifiers, false);
        }
    }

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: DimensionDynamicAccount

    So, I need to write my own code in method "onSegmentChanged". But I cannot find this method anywhere. It is not on the LedgerJournalTransDaily form and I cannot find anywhere to overwrite it from super().

    When I find that method, I think I can use "if (_segment.parmDimensionAttribute().RecId == myBusinessUnitAttribute)" to determine that it is the segment "BusinessUnit" (just before the "Site" segment) that has been changed. If that is the case, then I need help to save my string in the "Site" segment.

  • Suggested answer
    Pedro Tornich Profile Picture
    Pedro Tornich 955 on at
    RE: DimensionDynamicAccount

    You are right Morten,

    Since you have a Ledger Dimension the Main Account is mandatory and you won't be able to set the other dimensions before you set the Main Account.

    If you create a General Journal, fill some financial dimension on the header, then add a line to it, you will see that the account field (LedgerDimension) will remain empty until you pick the main account. Only after picking the main account, the journal engine will automatically fill the other dimensions based on the journal header.

    In other words you won't be able to do it on the initValue().

    The segmentedEntry control has a method called onSegmentChanged() where you can act if a specific dimension has changed.

    You can check the onSegmentChanged() method on the LedgerJournalTransDaily form:

    public void onSegmentChanged(DimensionControlSegment _segment)

    {

       // <GIN>

       if (TaxWithholdParameters_IN::checkTaxParameters() && ledgerJournalTrans.ledgerJournalTransTaxExtensionIN().TaxWithholdCode != '')

       {

           if (Box::okCancel("@GLS222698", DialogButton::Cancel) == DialogButton::Cancel)

           {

               return;

           }

       }

       // </GIN>

       if (_segment.parmDimensionAttribute().RecId == mainAccountDimAttr)

       {

           previousMainAccountId = currentMainAccountId;

       }

       super(_segment);

       currentMainAccountId = ledgerJournalEngine.onSegmentChangedForPrimaryAccount(ledgerJournalTrans_AccountNum, _segment, currentMainAccountId, ledgerJournalTrans);

    }

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: DimensionDynamicAccount

    Hi Pedro,

    Thank you very much for your help!

    I have a string variable with the value, I want to save in the "Site" part of the field. But when I in the initValue method use the code from daxtarkowski, it does not work.

    My _ledgerDimension variable is null. Maybe I should initialize it in some way?

    After his code, the variables defaultAccount and ledgerDimension is both null. As I understand it, I try to enter/merge my string variable into a field that is null and the result is null.

    I have also asked him...

  • Pedro Tornich Profile Picture
    Pedro Tornich 955 on at
    RE: DimensionDynamicAccount

    Hi Morten,

    There are basically two ways to change a dimension value, you can either change it by the dimension name or you can merge it with another dimension.

    The sample code I shared has the dimension name hardcoded for demonstration purposes, so you would need to change that to the name of you dimension.

    But it's not good to have it hardcoded, so you would need to create a parameter where the user could determine which one is the site dimension. Then you get the dimension name from this parameter.

    The other option is the way the LedgerJournalTrans table works, for example, it can initialize the financial dimension values from the customer account, merging the default dimension configured on the customer master with the current dimensions on the journal line (which will normally be empty at this time).

    The journal line does the same with the journal header, the journal header dimensions come from the journal name and when you add a new line the line is initialized with the header dimensions.

    If you have a customer, vendor, journal header or any other master entity that already has a default dimension, you can use it to initialize your field, this way you wouldn't need a new parameter to set the dimension name.

    Here is a sample code on how to merge a default dimension with an existing ledger dimension:

    DimensionDefaultingService::serviceCreateLedgerDimension(ledgerDimension, defaultDimension);

    You could use this to get the site dimension from a customer, for example.

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: DimensionDynamicAccount

    Hi Ludwig,

    Thank you for your reply.

    I am not sure I understand your question, because all this about dimensions is new to me.

    I am creating a new record and I don't know what to put in my LedgerDimension field. That is up to the user.

    Except for the "Site" part of the field. I know that and want to show it to the user, before he/she enters the LedgerDimension field. Then the user can enter MainAccount, BusinessUnit, CostCentre and Reporting - and change the "Site"-value if he/she wants.

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: DimensionDynamicAccount

    Hi Pedro,

    Thank you very much.

    My field is a LedgerDimension field. The user decides the main account and before he/she does that, I should enter a value in the "Site" part of the field. So I write my code in the initValue method.

    I use the code from your link to daxtarkowski.wordpress.com. But when I do that, my input parameter _ledgerDimension is null at first and defaultAccount and ledgerDimension is also null at the end of the method.

    I guess, I must make my _ledgerDimension into a new LedgerDimension only with blank values, before I use the code from daxtarkowski.

    How do I make this work during insert of a new record?

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: DimensionDynamicAccount

    Hello Morten,

    Why didn't you create financial dimensions for business unit, site, etc. ?

    It seems that you want to track all that information in a single field.

    Is that right?

    Best regards,

    Ludwig

  • Suggested answer
    Pedro Tornich Profile Picture
    Pedro Tornich 955 on at
    RE: DimensionDynamicAccount

    Hi Morten,

    If you are talking about a LedgerDimension field (I assume you are), then you can indeed fill the dimensions individually by code.

    But you can also default the dimension values based on the main account, check this thread for more information: community.dynamics.com/.../ax2012-financial-dimensions-default-value

    If you still need to change the dimension values by code you may check this blog post: daxtarkowski.wordpress.com/.../

    You should be able to fill the dimension as you want, within the insert method (before the super() call) or you could also add this logic to the initValue() method.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans