Hi All
I can populated global dimensions on sales invoice line from an API call using APIv2 architecture. However non global dimension codes are using a different logic and I'm unable to directly call them. Has anyone been able to insert sales invoice lines with shortcut dimensions using APIV2?
HI,
You can follow the below logic. to insert the shortcut dimension in sales invoice lines.
// After creating a global variable then add in to API as field.
field(VJ_Dimension3; VJ_DimensionCode[3])
{
ApplicationArea = All;
Caption = 'Dimension 3 Code';
}
// use the below logic to insert the dimension code through API.
trigger OnInsertRecord(BelowxRec: Boolean): Boolean
var
SalesInvoiceAggregator: Codeunit "Sales Invoice Aggregator";
begi
SalesInvoiceAggregator.PropagateInsertLine(Rec, TempFieldBuffer);
UpdateDimensionsOnSalesLine();
end;
local procedure UpdateDimensionsOnSalesLine()
var
Rec_SalesLine: Record "Sales Line";
Rec_SalesHeader: Record "Sales Header";
begin
Clear(Rec_SalesHeader);
Rec_SalesHeader.Reset();
if Rec_SalesHeader.GetBySystemId(Rec."Document Id") then begin
Clear(Rec_SalesLine);
Rec_SalesLine.Reset();
Rec_SalesLine.SetRange("Document Type", Rec_SalesLine."Document Type"::Invoice);
Rec_SalesLine.SetRange("Document No.", Rec_SalesHeader."No.");
Rec_SalesLine.SetRange("Line No.", Rec."Line No.");
if Rec_SalesLine.FindFirst() then begin
Rec_SalesLine.Validate("Shortcut Dimension 1 Code", VJ_DimensionCode[1]);
Rec_SalesLine.Validate("Shortcut Dimension 2 Code", VJ_DimensionCode[2]);
Rec_SalesLine.ValidateShortcutDimCode(3, VJ_DimensionCode[3]);
Rec_SalesLine.ValidateShortcutDimCode(4, VJ_DimensionCode[4]);
Rec_SalesLine.ValidateShortcutDimCode(5, VJ_DimensionCode[5]);
Rec_SalesLine.ValidateShortcutDimCode(6, VJ_DimensionCode[6]);
Rec_SalesLine.ValidateShortcutDimCode(7, VJ_DimensionCode[7]);
Rec_SalesLine.ValidateShortcutDimCode(8, VJ_DimensionCode[8]);
Rec_SalesLine.Modify(false);
end;
end
else
Error(SalesHeaderNotFoundErr, Rec."Document Id");
end;
// create a global variable
var
VJ_DimensionCode: Array[8] of Code[20];
If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,524 Super User 2024 Season 2
Martin Dráb 228,469 Most Valuable Professional
nmaenpaa 101,148