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;
Answers
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.
Johannes Sebastian
MB7-840,MB7-841
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.
Microsoft - Dynamics NAV
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!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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:
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.
Microsoft - Dynamics NAV
Thanks for another hint