We used the Document Dimension table to insert dimensions for Purchase Invoices in the past. With the new changes to Dimensions, we have to change the code to reflect the new way. I am trying to insert dimensions to the 480 Dimension Entry Set table object for new combinations of dimensions for the Purchase Invoice page line items. If they are already in the table, then I can set the Dimension Set ID and it is fine, but the problem is with new dimension combinations, I don’t know how to enter new dimension values for a document. Here is my old code how we inserted dimensions for lines in the Purchase Invoice records below. I am trying to replicate this code to work with the new 480 Dimension Set Entry table.
// test to see if it's a dimension value, and if so insert
IF STRPOS(FieldName, 'NavDim') > 0 THEN BEGIN
DimensionRef.OPEN(DATABASE::"Document Dimension");
strValue := 'WHERE (Document Type=FILTER(' + FORMAT(Rec."Document Type") +
'),Document No.=FILTER(' + Rec."No." + '),' +
'Line No.=FILTER(' + FORMAT((x + 1) * 10000) + '),' +
'Dimension Code=FILTER('+ FORMAT(StampValue.Value2) + '))';
DimensionRef.SETVIEW(strValue);
DimensionRef.DELETEALL(TRUE);
DimensionRef.GETTABLE(DimensionRec);
fieldNo := DimensionRec.FIELDNO("Table ID");
field := DimensionRef.FIELD(fieldNo);
field.VALIDATE(39); // purchase line table id
fieldNo := DimensionRec.FIELDNO("Document Type");
field := DimensionRef.FIELD(fieldNo);
field.VALIDATE( Rec."Document Type");
fieldNo := DimensionRec.FIELDNO("Document No.");
field := DimensionRef.FIELD(fieldNo);
field.VALIDATE( Rec."No.");
fieldNo := DimensionRec.FIELDNO("Line No.");
field := DimensionRef.FIELD(fieldNo);
field.VALIDATE((x + 1) * 10000);
fieldNo := DimensionRec.FIELDNO("Dimension Code");
field := DimensionRef.FIELD(fieldNo);
field.VALIDATE(StampValue.Value2);
fieldNo := DimensionRec.FIELDNO("Dimension Value Code");
field := DimensionRef.FIELD(fieldNo);
field.VALIDATE(StampValue.Value);
DimensionRef.INSERT(TRUE);
DimensionRef.CLOSE;
// if the dimension is one of the shortcut dimensions then insert the value
// in the purchase line
IF StampValue.Value2 = glSetup."Shortcut Dimension 1 Code" THEN BEGIN
fieldNo := lineRec.FIELDNO("Shortcut Dimension 1 Code");
field := lineref.FIELD(fieldNo);
field.VALUE := StampValue.Value;
END
ELSE IF StampValue.Value2 = glSetup."Shortcut Dimension 2 Code" THEN BEGIN
fieldNo := lineRec.FIELDNO("Shortcut Dimension 2 Code");
field := lineref.FIELD(fieldNo);
field.VALUE := StampValue.Value;
END;
END
0
Comments
IF STRPOS(FieldName, 'NavDim') > 0 THEN BEGIN
DimensionRec.VALIDATE("Dimension Code",'AREA');
DimensionRec.VALIDATE("Dimension Value Code",'10');
DimensionRec.INSERT(TRUE);
DimensionRec.GetDimensionSetID(DimensionRec);
DimSetID_L := dimCodeUnit.GetDimensionSetID(DimensionRec);
fieldNo := lineRec.FIELDNO("Dimension Set ID");
field := lineref.FIELD(fieldNo);
field.VALUE := DimSetID_L;
thank you
Don't *ever* directly insert or modify in tables 480 and 481.
The way to obtain the correct, new Dimension Set ID is (in pseudo code):
1) Declare a TempDimSetEntry as record 480, Temporary=Yes.
2) Declare DimMgt as codeunit 408.
3) Call DimMgt.GetDimensionSet(TempDimSetEntry,PurchLine."Dimension Set ID"); // now TempDimSetEntry contains the 'old' dimensions
4) Add/remove the dimensions you want from TempDimSetEntry.
5) Update the purchase line: PurchLine."Dimension Set ID" := DimMgt.GetDimensionSetID(TempDimSetEntry); // automatically creates new combinations if needed.
Microsoft - Dynamics NAV
You need to use a temporary Dimension Set ID and call GetDimensionSetID function of DimensionManagement codeunit.
Can you please check if this post can help you?