I am creating new fields for the Sales Quote page that are calculated from existing fields.
A Line Cost field that is calculated by multiplying Quantity and Unit Cost.
A Line Profit field that is calculated by subtracting Line Cost from Line Amount.
A summation of all Line Cost fields in Total Cost.
A summation of all Line Profit fields in Total Profit.
But I am receiving an exception that the Line Cost and Line Profit fields must be a member.
this is my code for the page extension:
pageextension 56005 PageExtension56005 extends "Sales Quote Subform"
{
layout
{
addafter("Line Amount")
{
field(LineCost; LineCost)
{
Caption = 'Line Cost';
ApplicationArea = All;
Editable = false;
Visible = false;
}
field(LineProfit; LineProfit)
{
Caption = 'Line Profit';
ApplicationArea = All;
Editable = false;
Visible = false;
}
}
addafter("Total Amount Incl. VAT")
{
field(TotalCost; TotalCost)
{
Caption = 'Total Cost';
ApplicationArea = All;
Editable = false;
}
field(TotalProfit; TotalProfit)
{
Caption = 'Total Profit';
ApplicationArea = All;
Editable = false;
}
}
}
trigger OnAfterGetRecord()
begin
end;
trigger OnAfterGetCurrRecord()
begin
UpdateLineCostAndLineProfit();
UpdateTotalCostAndTotalProfit();
end;
trigger OnInsertRecord(BelowxRec: Boolean): Boolean
begin
UpdateLineCostAndLineProfit();
UpdateTotalCostAndTotalProfit();
end;
trigger OnDeleteRecord(): Boolean
begin
UpdateLineCostAndLineProfit();
UpdateTotalCostAndTotalProfit();
end;
var
LineCost: Decimal;
LineProfit: Decimal;
TotalCost: Decimal;
TotalProfit: Decimal;
///
/// UpdateLineCostAndLineProfit.
///
procedure UpdateLineCostAndLineProfit()
var
SalesLine: Record "Sales Line";
begin
LineCost := 0;
LineProfit := 0;
SalesLine.Reset();
SalesLine.CopyFilters(Rec);
LineCost := Quantity * "Unit Cost";
LineProfit := "Line Amount" - LineCost;
end;
///
/// UpdateTotalCostAndTotalProfit.
///
procedure UpdateTotalCostAndTotalProfit()
var
SalesLine: Record "Sales Line";
begin
TotalCost := 0;
TotalProfit := 0;
SalesLine.Reset();
SalesLine.CopyFilters(Rec);
SalesLine.CalcSums(LineCost);
SalesLine.CalcSums(LineProfit);
TotalCost := SalesLine.LineCost;
TotalProfit := SalesLine.LineProfit;
end;
}
I am working on a Demo tenant with Business Central Sandbox Environment version 20.4