I am creating essentially an extension of the default get customer endpoint, but need to return dimensions as part of the /customers endpoint, so part() won't work for me. I presume I need to do something along the lines of this:
var
Dimensions: Text;
trigger OnAfterGetRecord()
var
TDimensions: Record "Default Dimension";
begin
TDimensions.Reset();
TDimensions.Get();
Dimensions := TDimensions."Dimension Code";
end;
But obviously need to pass in some "query" stuff to specify what data I want, but not really sure how. Any help is much appreciated.
Ideally I would like to have the full list of Dimensions
I am creating essentially an extension of the default get customer endpoint, but need to return dimensions as part of the /customers endpoint, so part() won't work for me. I presume I need to do something along the lines of this:
var
Dimensions: Text;
trigger OnAfterGetRecord()
var
TDimensions: Record "Default Dimension";
begin
TDimensions.Reset();
TDimensions.Get();
Dimensions := TDimensions."Dimension Code";
end;
But obviously need to pass in some "query" stuff to specify what data I want, but not really sure how. Any help is much appreciated.
Ideally I would like to have the full list of Dimensions
Share Improve this question asked Mar 20 at 14:56 Jack BraceyJack Bracey 531 silver badge6 bronze badges1 Answer
Reset to default 0For anyone interested in the future, this was the solution that worked for me. Thanks to Natin Verma on the Microsoft forums
var
Dimensions: Text;
trigger OnAfterGetRecord()
var
DefaultDimension: Record "Default Dimension";
DimensionText: Text;
begin
// Clear the Dimensions variable for each customer record
Dimensions := '';
// Filter Default Dimension records for the current customer
DefaultDimension.Reset();
DefaultDimension.SetRange("Table ID", Database::Customer); // Table ID for Customer table
DefaultDimension.SetRange("No.", Rec."No."); // Filter by the current customer's No.
// Loop through all dimensions for the customer
if DefaultDimension.FindSet() then begin
repeat
// Append each dimension code to the text (e.g., "DEPARTMENT,PROJECT")
if DimensionText = '' then
DimensionText := DefaultDimension."Dimension Code"
else
DimensionText := DimensionText + ',' + DefaultDimension."Dimension Code";
until DefaultDimension.Next() = 0;
end;
// Assign the concatenated dimension codes to the Dimensions field
Dimensions := DimensionText;
end;