actions { addfirst(processing) { action(UpdateSalesHeaderDimensions) { Caption = 'Test Update Sales Header Dimensions'; ApplicationArea = all; trigger OnAction() var DimVal: Record "Dimension Value"; TempDimSetEntry: Record "Dimension Set Entry" temporary; DimMgt: Codeunit DimensionManagement; begin // Dimension 1 (Location) DimVal.GET('LOCATION DIM', 'MEL'); TempDimSetEntry.INIT(); TempDimSetEntry.VALIDATE("Dimension Code", DimVal."Dimension Code"); TempDimSetEntry.VALIDATE("Dimension Value Code", DimVal.CODE); TempDimSetEntry."Dimension Value ID" := DimVal."Dimension Value ID"; TempDimSetEntry.INSERT(); // Dimension 2 (Department) DimVal.GET('DEPARTMENT', 'SERVICE'); TempDimSetEntry.INIT(); TempDimSetEntry.VALIDATE("Dimension Code", DimVal."Dimension Code"); TempDimSetEntry.VALIDATE("Dimension Value Code", DimVal.CODE); TempDimSetEntry."Dimension Value ID" := DimVal."Dimension Value ID"; TempDimSetEntry.INSERT(); // Dimension 3 (Area) DimVal.GET('AREA', '30'); TempDimSetEntry.INIT(); TempDimSetEntry.VALIDATE("Dimension Code", DimVal."Dimension Code"); TempDimSetEntry.VALIDATE("Dimension Value Code", DimVal.CODE); TempDimSetEntry."Dimension Value ID" := DimVal."Dimension Value ID"; TempDimSetEntry.INSERT(); // Dimension 4 (salesperson) DimVal.GET('SALESPERSON', 'JO'); TempDimSetEntry.INIT(); TempDimSetEntry.VALIDATE("Dimension Code", DimVal."Dimension Code"); TempDimSetEntry.VALIDATE("Dimension Value Code", DimVal.CODE); TempDimSetEntry."Dimension Value ID" := DimVal."Dimension Value ID"; TempDimSetEntry.INSERT(); Rec."Dimension Set ID" := DimMgt.GetDimensionSetID(TempDimSetEntry); Rec.Modify(true); end; } } } }
samantha73 wrote: »Is there a better way to handle this with shorter code?
samantha73 wrote: »Also instead of passing dimension code like 'AREA' can we say shortcutdimension3code so if someone change the name it wont break?
Answers
You should likely use SalesHeader.CreateDim, or even make provisions that SalesHeader.CreateDimFromDefaultDim does the right thing anyway.
If you must use GetDimensionSetID for any compelling reason you SHOULD
You can configure which shortcut dimensions correspond to which dimensions. So switching from dimension code to shortcut dimension number probably makes things worse, not better, because renaming a dimension is handled transparently thorougout the system, but re-assigning shortcut dimensions is not. Moreover, your requirement to update certaing dimension values probably is tied to the dimension, and neither to the dimension code, nor to the assignment of that dimension to a global dimension or shortcut dimension. Use a Setup!