Help 2013r2 Trouble Upgrading UpdateDimensions function

itsandsllcitsandsllc Member Posts: 13
edited 2013-11-18 in NAV Three Tier
Hello all I am working on my first upgrade to 2013 r2 that I have inherited and trying to upgrade a database with a lot of dimension based modifications, no documentation and the client has no clue about what has been done under the covers for them. I have just started with 2013 and only done one other upgrade at this time. I have my c/side solution development in nav 2013 and chapter 8 - Module Dimensions open but I am having some trouble understanding how I should use the new calls to upgrade the following code. I have searched and been trying for a few hours but I am not getting the same results as used to occur on NAV 5. I know this is surely trivial for some but any inputs would be much appreciated; I'm sorry to say that the majority of my experiance with dimensions has been in setup and reporting. I have been just fine adapting to other changes but could really use some help here.

#-o

Thanks in advance for any and all replys :)

Current Code ::

Function UpdateDimensions() is on table 38 Purchase Header and I have just about the same function on the lines; I should also mention the customer no. is the same as global dim 2. Thats why there is the call from the customer.

Vars:
Name | DataType | Subtype | Length
GeneralLedgerSetup | Record | General Ledger Setup
Customer | Record | Customer
DefaultDimension |Record | Default Dimension
DocumentDimension | Record | Used to be Document Dimension Table 357
ChangeDimensions()
IF Customer.GET("Shortcut Dimension 2 Code") THEN BEGIN
  GeneralLedgerSetup.GET;
  DefaultDimension.SETRANGE("Table ID", 18);
  DefaultDimension.SETRANGE("No.","Shortcut Dimension 2 Code");
  IF DefaultDimension.FINDFIRST THEN REPEAT
    IF DefaultDimension."Dimension Code" = GeneralLedgerSetup."Global Dimension 1 Code" THEN
      VALIDATE("Shortcut Dimension 1 Code", DefaultDimension."Dimension Value Code")
    ELSE
      IF DefaultDimension."Dimension Code" <> "Shortcut Dimension 2 Code" THEN
        IF DocumentDimension.GET(DATABASE::"Purchase Header","Document Type","No.",0,DefaultDimension."Dimension Code") THEN BEGIN
          DocumentDimension.VALIDATE("Dimension Value Code", DefaultDimension."Dimension Value Code");
          DocumentDimension.MODIFY(TRUE);
        END ELSE BEGIN
          CLEAR(DocumentDimension);
          DocumentDimension.VALIDATE("Table ID",DATABASE::"Purchase Header");
          DocumentDimension.VALIDATE("Document Type", "Document Type");
          DocumentDimension.VALIDATE("Document No.", "No.");
          DocumentDimension.VALIDATE("Line No.", 0);
          DocumentDimension.VALIDATE("Dimension Code", DefaultDimension."Dimension Code");
          DocumentDimension.VALIDATE("Dimension Value Code", DefaultDimension."Dimension Value Code");
          DocumentDimension.INSERT(TRUE);
        END;
  UNTIL DefaultDimension.NEXT = 0;
END;

Thanks again for any help.

Comments

  • geordiegeordie Member Posts: 655
    Hi, you can take advantage from new dimension management in NAV 2013 where Document Dimension, Posted Document Dimension and so on are replace by a unique new table called Dimension Set Entry, whose primary key is an integer evaluated through DimensionManagement codeunit.
    According to this I suggest to modify your function as follow:
    PROCEDURE UpdateDimensions@1101321000();
        VAR
          Customer@1101321000 : Record 18;
          GeneralLedgerSetup@1101321001 : Record 98;
          DefaultDimension@1101321002 : Record 352;
          TempDimSetEntry@1101321005 : TEMPORARY Record 480;
          DimMgt@1101321004 : Codeunit 408;
          OldDimSetID@1101321003 : Integer;
          NewDimSetID@1101321006 : Integer;
        BEGIN
          IF Customer.GET("Shortcut Dimension 2 Code") THEN BEGIN
            GeneralLedgerSetup.GET;
            DefaultDimension.SETRANGE("Table ID", 18);
            DefaultDimension.SETRANGE("No.","Shortcut Dimension 2 Code");
            IF DefaultDimension.FINDFIRST THEN
              REPEAT
                OldDimSetID := "Dimension Set ID";
                DimMgt.GetDimensionSet(TempDimSetEntry,OldDimSetID); //Get existing purchase order header dimensions
    
                TempDimSetEntry.SETRANGE("Dimension Code",DefaultDimension."Dimension Code");
    
                IF DefaultDimension."Dimension Code" = GeneralLedgerSetup."Global Dimension 1 Code" THEN
                    VALIDATE("Shortcut Dimension 1 Code",DefaultDimension."Dimension Value Code")
                ELSE
                  IF DefaultDimension."Dimension Code" <> "Shortcut Dimension 2 Code" THEN
                    IF TempDimSetEntry.FINDFIRST THEN
                      TempDimSetEntry.VALIDATE("Dimension Value Code", DefaultDimension."Dimension Value Code")
                    ELSE BEGIN
                      TempDimSetEntry.INIT;
                      TempDimSetEntry.VALIDATE("Dimension Code", DefaultDimension."Dimension Code");
                      TempDimSetEntry.VALIDATE("Dimension Value Code", DefaultDimension."Dimension Value Code");
                      TempDimSetEntry.INSERT;
                    END;
              UNTIL DefaultDimension.NEXT = 0;
    
            NewDimSetID := DimMgt.GetDimensionSetID(TempDimSetEntry); //Get new DimSetID, after existing dimensions are modified
    
            IF OldDimSetID <> NewDimSetID THEN BEGIN
              "Dimension Set ID" := NewDimSetID;
              MODIFY;
    
              //Synchronize shortcut and global dimensions with the dimension set
              DimMgt.UpdateGlobalDimFromDimSetID("Dimension Set ID","Shortcut Dimension 1 Code","Shortcut Dimension 2 Code");
            END;
    
          END;
        END;
    

    Hope it works fine, I'm in a hurry and I didn't test it :oops:
  • itsandsllcitsandsllc Member Posts: 13
    Hey geordie thanks so much for your response =D> I really appreciate it. I’m mowing over the code and running some tests on it. I can see now how you changed the code around and really appreciate the inputs.

    I will post back and let you know how the testing turns out.

    Thanks again so much for the help :)
Sign In or Register to comment.