How to calculate Dimension Set ID

Starting from Dynamics NAV 2013, dimension’s structure has changed a lot. Since then, a lot of developers struggle to insert or update dimensions pragmatically.

I will not bother you with what was already explained a hundred times in other blogs on how to calculate Dimension Set ID. Better, I will share with you a simple codeunit “SpecDimensionManagement” that will save you time whenever you will need to update dimensions (by update I mean Create, Update, Delete).

In order to use my codeunit, I invite you respect the following example:

WITH SpecDimensionManagement DO BEGIN
// Get Current Dimension Set ID or init a new one
INIT(MyRecord);
// Update my dimensions values
UPDATE(‘DIM1’, ‘VALUE1’);
UPDATE(‘DIM2’, ‘VALUE2’);
UPDATE(‘DIM3’, ‘VALUE3’);
DELETE(‘DIM4’);
DELETE(‘DIM5’);
DELETE(‘DIM6’);
// Calculate my new Dimension Set ID
MyRecord.”Dimension Set ID” := GetDimSetID;
// Get new values if needed
GetCurrDimValues(DimCode, DimValueCode, MyRecord.”Dimension Set ID”);
END;

I put some comments to explain what the functions do.

In the fob, you’ll find codeunit 92600 that handle the calculation and codeunit 92601 where I create some examples for test.

Feel free to contact me if you need more details / informations. Share your ideas and feedback in comment section 🙂

P.S: the fob is from a NAV 2015 FR (Build 49000) database. I test it on NAV 2017 and 2016 also.

This blog is available also on Microsoft Dynamics NAV Community

9 Comments

  1. Matt

    I came across this trying to understand how dim set ids work. Let me say, this was very helpful to me and I was able to solve my problem.
    I do however think that this is far more complicated than needed. All I am doing is removing and updating an existing dim set, then getting a new id. So copy into a temp, make your changes (pass by array if multiple), then call the dim mgmt cu to get your new id. Done.It’s like a dozen lines.

    • NavNab

      Hello Matt,

      I’m glad you resolved your problem.
      The idea behind this codeunit is to help junior developers who are not familiar with TempDimensionSetEntry and also lazy developers who do not wat to write the same code forever (the dozen lines you just wrote) 🙂

  2. Narinder

    Someone from my team deleted all the Dimension Set Entry and Dimension Set Tree Node table. After that there has been error while posting that Dimension must be there in case G/L Account ******. So I debugged the issue and found that the Value entry has Old Dimension Set Id(which are now deleted). So is there any way we can update the Dimension Set id in Value Entry table without disturbing anything in the system.

    • NavNab

      Hello,

      Sorry for the very very very late answer.
      A part from getting a database backup and try to restore data I can’t think of other solutions (for now). Maybe you could share what you have done to resolve your problem. That will be always helpful for someone somewhere “somewhen” 😉

  3. Sombo

    the download zip file in the docx is no longer available.

    • NavNab

      Hi,

      I just checked and the fob is available. You can copy/past the zip from the docx to your desktop then open it.

  4. gtr

    Hello, Tried out the code – updates are TEMPORARY so finally documents are not really updated ? And procedure CopyTempDimensionSetEntry is not used. Can you explain ? Best Regards

    • NavNab

      Hello,

      To update the record (document as you say) you should use these lines in your code:
      MyRecord.”Dimension Set ID” := GetDimSetID;
      MyRecord.MODIFY(TRUE); // this line is not in the example I gave but this should because do the trick. It depends on how you code. Maybe the MODIFY should be placed somewhere later in your code 😉
      Or maybe
      MyRecord.VALIDATE(“Dimension Set ID”, GetDimSetID);
      MyRecord.MODIFY(TRUE);

      In the Codeunit, I included other functions (CopyTempDimensionSetEntry for example) that a developer can use for other purpose. I assume these functions are self explanatory. But, maybe you can share your use case and I’ll try to give you hints on how to write a proper code 😉

      • toolasi

        Hello – i asked to be sure – but I added the code to update the record and all went fine
        Thanks a lot

Leave a Reply to Matt Cancel reply

Your email address will not be published.

© 2022 NAV NAB BLOG

Theme by Anders NorenUp ↑