Business Central - purchase line - update shortcut/global dimensions
DmitriySozinov
Member Posts: 23
Good day,
I am looking for a hint on how to update shortcut dimension codes on a purchase line, after an update to line dimension values.
Here is the code I use to update the purchase line dimensions with values from external system:
It works fine - line dimension values are updated by values from external system, but the shortcut dimension values remain blank.
Is it a call to DimMgt.ValidateShortcutDimValues that I am missing?
If so, what is the FieldNumber parameter? Is it the number of the shorcut/global dimension in the gl setup?
Thank you.
I am looking for a hint on how to update shortcut dimension codes on a purchase line, after an update to line dimension values.
Here is the code I use to update the purchase line dimensions with values from external system:
procedure AssignLineDimension(DocumentType: Integer; DocumentNumber: Code[20]; LineNo: Integer; DimensionCode: Code[20]; DimensionValue: Code[20]);
var
TempDimSetEntry: Record "Dimension Set Entry" temporary;
PurchaseLine: Record "Purchase Line";
DimMgt: Codeunit DimensionManagement;
NewDimSetID: Integer;
OldDimSetID: Integer;
begin
PurchaseLine.Get(DocumentType, DocumentNumber, LineNo);
//obtain current line dimension set id and its dimensions
OldDimSetID := PurchaseLine."Dimension Set ID";
DimMgt.GetDimensionSet(TempDimSetEntry, OldDimSetID);
//assign new/update existing dimension with data from external system
TempDimSetEntry.Reset();
TempDimSetEntry.SetRange("Dimension Code", DimensionCode);
if TempDimSetEntry.FindFirst() then begin
TempDimSetEntry.Validate("Dimension Value Code", DimensionValue);
TempDimSetEntry.Modify();
end
else begin
TempDimSetEntry.Init();
TempDimSetEntry.Validate("Dimension Code", DimensionCode);
TempDimSetEntry.Validate("Dimension Value Code", DimensionValue);
TempDimSetEntry.Insert();
end;
//obtain DimSetID after line dimension update
NewDimSetID := DimMgt.GetDimensionSetID(TempDimSetEntry);
//update line dimension set id
if OldDimSetID <> NewDimSetID then begin
PurchaseLine."Dimension Set ID" := NewDimSetID;
PurchaseLine.Modify();
end;
//update line's global dimensions
DimMgt.UpdateGlobalDimFromDimSetID(PurchaseLine."Dimension Set ID", PurchaseLine."Shortcut Dimension 1 Code", PurchaseLine."Shortcut Dimension 2 Code");
end;
It works fine - line dimension values are updated by values from external system, but the shortcut dimension values remain blank.
Is it a call to DimMgt.ValidateShortcutDimValues that I am missing?
If so, what is the FieldNumber parameter? Is it the number of the shorcut/global dimension in the gl setup?
Thank you.
1
Best Answer
-
Adding this code made the trick:
... //update line's global dimensions GLSetup.Get(); if DimensionCode = GLSetup."Global Dimension 1 Code" then begin PurchaseLine.Validate("Shortcut Dimension 1 Code", DimensionValue); PurchaseLine.Modify(); end; if DimensionCode = GLSetup."Global Dimension 2 Code" then begin PurchaseLine.Validate("Shortcut Dimension 2 Code", DimensionValue); PurchaseLine.Modify(); end; //obtain DimSetID after line dimension update ...
This way, the onValidate trigger of the table field handles the call to DimMgt.ValidateShortcutDimValues
0
Answers
-
"FieldNumber" is a reference to the number the dimension code has in GL Setup.
Dimension 1 = field 1 and so on
It's used to point the dimension value to the correct dimension code
That is correctIf so, what is the FieldNumber parameter? Is it the number of the shorcut/global dimension in the gl setup?0 -
Adding this code made the trick:
... //update line's global dimensions GLSetup.Get(); if DimensionCode = GLSetup."Global Dimension 1 Code" then begin PurchaseLine.Validate("Shortcut Dimension 1 Code", DimensionValue); PurchaseLine.Modify(); end; if DimensionCode = GLSetup."Global Dimension 2 Code" then begin PurchaseLine.Validate("Shortcut Dimension 2 Code", DimensionValue); PurchaseLine.Modify(); end; //obtain DimSetID after line dimension update ...
This way, the onValidate trigger of the table field handles the call to DimMgt.ValidateShortcutDimValues
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 326 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions