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

Sum of lineitems price on TotalPrice field using AL code

(0) ShareShare
ReportReport
Posted on by

Hi I am working on Custom page and table using al code. On page WarRegFormItemLinkSubLinePage, I am getting price using flowfield from WarrantyProductSubline page, which is working fine. However, I am not getting sum of lines in TotalPrice field. It's giving me only one row price, not sum up the price of all lines, when I do trigger on item no field. I am running trigger using procedure UpdatePrice(). Please help me to find where I am doing mistake. Thank You

table 50108 WarRegFormItemLinkSubLine
{
Caption = 'WarRegFormItemLinkSubLine';
/* DataCaptionFields = "No.", PName; */
fields
{
field(50100; "No."; Integer)
{
Caption = 'No.';
}
field(50101; "No. Series"; Code[20])
{
Caption = 'No. Series';
Editable = false;
TableRelation = "No. Series";
}
field(50102; "WarrantyRegNo"; code[20])
{
Caption = 'WarrantyRegNo.';
TableRelation = WarrantyReg."No.";
}
field(50103; "WarrantyFormNo"; code[20])
{
TableRelation = WarrantyReg.WarrantyFormNo;
}
field(50104; "WarrantyForm"; Text[900])
{
FieldClass = FlowField;
CalcFormula = lookup ("Warranty Forms".Name where("No." = field(WarrantyFormNo)));
}
field(50105; "ItemNo."; Text[900])
{
Caption = 'Item No.';
TableRelation = WarrantyProductSubLine."ItemNo." where("WFNo." = field(WarrantyFormNo));
}
field(50106; "ItemDesc."; Text[900])
{
Caption = 'Item Desc.';
FieldClass = FlowField;
CalcFormula = lookup (Item.Description where("No." = field("ItemNo.")));
}

field(50107; "Price"; Decimal)
{
Caption = 'Price';
FieldClass = FlowField;
CalcFormula = Sum (WarrantyProductSubLine.Price
WHERE("WFNo." = FIELD(WarrantyFormNo), "ItemNo." = FIELD("ItemNo.")));
}
field(50108; "TotalPrice"; Decimal)
{
Caption = 'Total Price';
}
}

keys
{
key(PK; "WarrantyRegNo", "No.", WarrantyFormNo, GenProGrup, TaxProGrup)
{
Clustered = true;
}
}

var
myInt: Integer;

}

page 50112 WarRegFormItemLinkSubLinePage

{
AutoSplitKey = false;
Caption = 'Lines';
DelayedInsert = true;
LinksAllowed = false;
MultipleNewLines = true;
PageType = ListPart;
SourceTable = WarRegFormItemLinkSubLine;


layout
{
area(Content)
{
repeater(Lines)
{
ShowCaption = false;
field("No."; "No.")
{
ApplicationArea = All;
Visible = true;
}
field(WarrantyRegNo; WarrantyRegNo)
{
ApplicationArea = All;
Visible = false;
Editable = false;
}
field(WarrantyFormNo; WarrantyFormNo)
{
ApplicationArea = All;
Caption = 'Warranty Form';
ToolTip = 'Specifies the WarrantyForm of the WarrantyForm.';
Visible = false;
Editable = true;

}
field(WarrantyForm; WarrantyForm)
{
ApplicationArea = All;
Caption = 'Warranty Form Name';
ToolTip = 'Specifies the WarrantyForm of the WarrantyForm.';
Visible = false;
Editable = false;
}
field("ItemNo."; "ItemNo.")
{
ApplicationArea = All;
Caption = 'Item No.';
Visible = true;
Editable = true;
trigger OnValidate()
var
begin
UpdatePrice();
CurrPage.Update();
end;
}
field("ItemDesc."; "ItemDesc.")
{
ApplicationArea = All;
Caption = 'Item Description';
Visible = true;
Editable = false;
}
field("Price"; Price)
{
ApplicationArea = All;
Caption = 'Price';
Visible = true;
Editable = true;
}
}
group("")
{
grid(MyGrid)
{
field("TotalPrice"; TotalRate2)
{
ApplicationArea = All;
Caption = 'Total Price';
trigger OnValidate()
begin
Error('You cannot edit this field.');
end;
}
}
}
}
}

actions
{
area(Processing)
{
action(ActionName)
{
ApplicationArea = All;

trigger OnAction()
begin

end;
}
}
}

trigger OnNewRecord(BelowxRec: Boolean)
var
WRFILSTable: Record WarRegFormItemLinkSubLine;
begin
WRFILSTable.RESET;
WRFILSTable.SETCURRENTKEY("No.");
IF WRFILSTable.FINDLAST THEN Begin
/* MESSAGE('%1', WFTable."No."); */
"No." := WRFILSTable."No." + 10;
End;
end;

procedure UpdatePrice()
var
WPS: Record WarrantyProductSubLine;
WFIS: Record WarRegFormItemLinkSubLine;
begin
TotalRate1 := 0.0;
WPS.SetRange(WPS."WFNo.", WarrantyFormNo);
WPS.SetRange(WPS."ItemNo.", "ItemNo.");
IF WPS.FIND('-') THEN
REPEAT
TotalRate1 += WPS.Price;
MESSAGE('Amount 1: %1', TotalRate1);
UNTIL WPS.NEXT = 0;
TotalRate2 := TotalRate1;
MESSAGE('t1: %1', TotalRate1);
end;

var
TotalRate1: Decimal;
TotalRate2: Decimal;
TotalQty1: Integer;
TotalQty2: Integer;
Desc: Text[900];
myInt: Integer;

}

I have the same question (0)
  • Suggested answer
    Robert Bulugea Profile Picture
    70 on at

    At first I would re-write that block a bit and rename those pages and tables as they seem a  bit confusing.

    Rewrite the block like this:

    WPS.RESET();

    WPS.SetRange(WPS."WFNo.", WarrantyFormNo);

    WPS.SetRange(WPS."ItemNo.", "ItemNo.");

    IF WPS.FINDSET(FALSE,FALSE) THEN

    REPEAT

     TotalRate1 += WPS.Price;  //Question, is Price a field or Flowfield, I suppose field as it works in your other flowfield calculation

     MESSAGE('Amount 1: %1', TotalRate1);

    UNTIL WPS.NEXT() = 0;

    "Total Price" := TotalRate1 ;

    Instead of TotalRate2, create a new field "Total Price". See if that works?

  • Community Member Profile Picture
    on at

    Yes price is a flowfield, I will try this way.

  • Community Member Profile Picture
    on at

    Still, It's not giving me sum up of price.

  • Suggested answer
    Robert Bulugea Profile Picture
    70 on at

    If price is a flowfield you need to run a calcfields on it and it will work in both ways, the way you had it and the way I said you could make it.

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 2,362

#2
YUN ZHU Profile Picture

YUN ZHU 867 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans