NAV 2013 - dimensions

Sl1m4erSl1m4er Member Posts: 42
edited 2013-06-06 in NAV Three Tier
Hi guys,

I have a problem upgrading our vertical solution for NAV 2013. Mainly related to the new architecture of dimensions area.

Our solution allows importing dimensions from external system for purchase orders and purchase journals.

Previously, in case of purchase orders all you had to do is to populate Document Dimension table with the dimensions from the external system, for example, as follows:
UpdatePurchaseHeaderDimensions(PurchaseHeaderLoc : Record "Purchase Header")
// InboundDocDimensions - dimensions from external system
InboundDocDimension.RESET;
InboundDocDimension.SETRANGE("Company ID","Company ID");
InboundDocDimension.SETRANGE("Table ID",DATABASE::"Inbound Purchase Header");
InboundDocDimension.SETRANGE("Document Type",InboundDocDimension."Document Type"::"Purchase Order");
InboundDocDimension.SETRANGE("Document No.","Approval No.");
InboundDocDimension.SETRANGE("Line No.",0);
IF InboundDocDimension.FINDSET THEN
  REPEAT
    IF Dimension.GET(InboundDocDimension."Dimension Code") THEN
      IF DimensionValue.GET(InboundDocDimension."Dimension Code",InboundDocDimension."Dimension Value Code") THEN
      BEGIN
        DocumentDimension.SETRANGE("Table ID",DATABASE::"Purchase Header");
        DocumentDimension.SETRANGE("Document Type",DocumentDimension."Document Type"::Order);
        DocumentDimension.SETRANGE("Document No.",PurchaseHeaderLoc."No.");
        DocumentDimension.SETRANGE("Line No.",0);
        DocumentDimension.SETRANGE("Dimension Code",InboundDocDimension."Dimension Code");
        IF DocumentDimension.FINDSET THEN
          REPEAT
            DocumentDimension."Dimension Value Code" := InboundDocDimension."Dimension Value Code";
            DocumentDimension.MODIFY;
          UNTIL DocumentDimension.NEXT = 0
        ELSE BEGIN
          DocumentDimension.INIT;
          DocumentDimension."Table ID" := DATABASE::"Purchase Header";
          DocumentDimension."Document Type" := DocumentDimension."Document Type"::Order;
          DocumentDimension."Document No." := PurchaseHeaderLoc."No.";
          DocumentDimension."Line No." := 0;
          DocumentDimension."Dimension Code" := InboundDocDimension."Dimension Code";
          DocumentDimension."Dimension Value Code" := InboundDocDimension."Dimension Value Code";
          DocumentDimension.INSERT;
        END;
      END;
  UNTIL InboundDocDimension.NEXT = 0;

Then purchase order dimensions would be updated with the dimensions from external system.

Now, DocumentDimension table is gone and a new table is introduced - Dimension Set Entry.
Unfortunately, I was not able to find a simple way to re-write the code above to work the same way in NAV 2013. And thus asking you for help.

I was thinking about the following algorithm:
- get current dimensionSetID of the purchase order
- find corresponding dimension set in Dimension Set Entry table
- for each dimension from external system:
--- validate dimension code in Dimension Set Entry table
--- validate dimension value in Dimension Set Entry table
- update current DimensionSetID value with the newly assigned one and modify purchase order

The questions I did not find the answers yet are:
- how do I secure that after updating Dimension Set Entry table, a new Dimension Set ID value is assigned. Is it necessary to run certain DimMgt functions for that?
- how can I obtain newly assigned Dimension Set ID value. What function is used for that?

In case someone can provide a simple solution, where the code would modify existing and add new dimensions for a pre-defined purchase order no. - it would help a lot.

Thanks in advance.

Answers

  • Johannes_NielsenJohannes_Nielsen Member Posts: 206
    Some new functions are added and many more has been removed making some things alot simpler.

    In your case, It think you just need to validate the values and it will update the Dim. Set ID field (480).

    But please check out Chapter 8 in the NAV 2013 "C/SIDE Solution Develpment" Course 80437.

    It's really comprehensive and every single function in DimensionManagement Codeunit is described.

    You can get it on Partner/Customer Source.
    Best regards / Venlig hilsen
    Johannes Sebastian
    MB7-840,MB7-841
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    In short; what you should do is:
    1. copy the external document dimensions into a TempDimSetEntry table (temp table based on table 480).
    2. call this function in codeunit 408:
    "Dimension Set ID" := DimMgt.GetDimensionSetID(TempDimSetEntry);
    and voilà; you have your new dimension set id to put on the table.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • krikikriki Member, Moderator Posts: 9,112
    In short; what you should do is:
    1. copy the external document dimensions into a TempDimSetEntry table (temp table based on table 480).
    2. call this function in codeunit 408:
    "Dimension Set ID" := DimMgt.GetDimensionSetID(TempDimSetEntry);
    and voilà; you have your new dimension set id to put on the table.

    A lot easier and faster than before!
    And if you know that your dimensions are the same for the records you import, you just need to run the above code once. After that you can always use the same "Dimension Set ID" value in all your records!
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Sl1m4erSl1m4er Member Posts: 42
    Hi guys,

    Thanks for your replies.
    Hint from Bardur Knudsen made the trick and all I had to do is to:

    1. Obtain a list of existing dimensions assigned to a purchase header, using 'Dimension Set ID' on purchase header and 'DimMgt.GetDimensionSet' function
    2. Update TempDimSetEntry table with dimensions from external system
    3. Generate new DimSetID using 'DimMgt.GetDimensionSetID' function
    3. Update 'Dimension Set ID' on purchase header with new 'Dimension Set ID' generated in step3, if needed.

    So, the code from the initial post now looks like this:
    UpdatePurchaseHeaderDimensions(PurchaseHeaderLoc : Record "Purchase Header")
    OldDimSetID := PurchaseHeaderLoc."Dimension Set ID";
    DimMgt.GetDimensionSet(TempDimSetEntry,OldDimSetID); //obtain list of existing purchase order dimensions
    
    InboundDocDimension.RESET;
    InboundDocDimension.SETRANGE("Company ID","Company ID");
    InboundDocDimension.SETRANGE("Table ID",DATABASE::"Inbound Purchase Header");
    InboundDocDimension.SETRANGE("Document Type",InboundDocDimension."Document Type"::"Purchase Order");
    InboundDocDimension.SETRANGE("Document No.","Approval No.");
    InboundDocDimension.SETRANGE("Line No.",0);
    IF InboundDocDimension.FINDSET THEN
      REPEAT
        TempDimSetEntry.RESET;
        TempDimSetEntry.SETRANGE("Dimension Code",InboundDocDimension."Dimension Code");
        IF TempDimSetEntry.FINDFIRST THEN BEGIN
          TempDimSetEntry.VALIDATE("Dimension Value Code",InboundDocDimension."Dimension Value Code");
          TempDimSetEntry.MODIFY;
        END
        ELSE BEGIN
          TempDimSetEntry.INIT;
          TempDimSetEntry.VALIDATE("Dimension Code",InboundDocDimension."Dimension Code");
          TempDimSetEntry.VALIDATE("Dimension Value Code",InboundDocDimension."Dimension Value Code");
          TempDimSetEntry.INSERT;
        END;
      UNTIL InboundDocDimension.NEXT = 0;
    
    NewDimSetID := DimMgt.GetDimensionSetID(TempDimSetEntry); //get new DimSetID, after existing PO dimensions are modified
    
    IF OldDimSetID <> NewDimSetID THEN BEGIN
      PurchaseHeaderLoc."Dimension Set ID" := NewDimSetID; //assign new DimSetID to Purchase Order
      PurchaseHeaderLoc.MODIFY;
    END;
    
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    Good.
    What you might want to add, is something like:

    DimMgt.UpdateGlobalDimFromDimSetID(PurchaseHeaderLoc."Dimension Set ID",PurchaseHeaderLoc."Shortcut Dimension 1 Code",PurchaseHeaderLoc."Shortcut Dimension 2 Code");

    In this way your shortcut / global dimensions are in sync with the dimension set.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • Sl1m4erSl1m4er Member Posts: 42
    Good.
    What you might want to add, is something like:

    DimMgt.UpdateGlobalDimFromDimSetID(PurchaseHeaderLoc."Dimension Set ID",PurchaseHeaderLoc."Shortcut Dimension 1 Code",PurchaseHeaderLoc."Shortcut Dimension 2 Code");

    In this way your shortcut / global dimensions are in sync with the dimension set.

    Thanks for another hint :)
Sign In or Register to comment.