web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Sales Quote Subform calculated fields

(0) ShareShare
ReportReport
Posted on by 77

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

  • Suggested answer
    Amit Baru Profile Picture
    3,043 on at

    Hi,

    pls write code on this trigger only.

    trigger OnAfterGetRecord()

       begin

            UpdateLineCostAndLineProfit();

           UpdateTotalCostAndTotalProfit();

       end;

    Regards

    Amit Sharma

    www.erpconsultors.com

    linkedin.com/in/amit-sharma-94542440/

    Press Yes if info is right.

  • chigivigi Profile Picture
    77 on at

    I have updated the extension. Now it only has the OnAfterGetRecord, but I am having the same error for LineCost and LineProfit fields.

    The error message on packaging the extensions are:

    error AL0166: Argument 1: must be a member

    For LineCost and LineProfit fields when calling UpdateTotalCostAndTotalProfit procedure and executing the SalesLine.CalcSums(LineCost)

    and SalesLine.CalcSums(LineProfit) methods.

    Also my Sales Line Record does not contain the definitions for LineCost and LineProfit.

    error AL0132: 'Record "Sales Line"' does not contain a definition for 'LineCost'

    error AL0132: 'Record "Sales Line"' does not contain a definition for 'LineProfit'

    This is my current extension code:

    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;
                }
            }
        }
    
        actions
        {
        }
    
        trigger OnAfterGetRecord()
        begin
            UpdateLineCostAndLineProfit();
            UpdateTotalCostAndTotalProfit();
        end;
    
            // trigger OnInsertRecord(BelowxRec: Boolecn): Boolnan Boolean  // begin
             // 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;
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 710 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 387 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 385 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans