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

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    Amit Baru Profile Picture
    3,037 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,226

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,047 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,257 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans