Hi All,
I'm doing a customization for Sales Order Card. The requirement is to add a new item line when releasing Sales Order. Adding a new line works fine. following is a code sample used for that.
pageextension 50100 SalesOrderExt extends "Sales Order" { layout { } actions { modify(Release) { trigger OnBeforeAction() var SalesHeader: Record "Sales Header"; AddPotLevyItem: Codeunit "Add Pot Levy Item"; begin SalesHeader.Copy(Rec); AddPotLevyItem.AddItem(SalesHeader); end; } } }
please note that, Amount of the new item is calculated from existing sales lines values.
procedure AddItem(SalesHeader: Record "Sales Header") var SalesLine: Record "Sales Line"; PotLevyAmount: Decimal; NewLineNo: Integer; NewSalesLine: Record "Sales Line"; ItemType: Enum "Sales Line Type"; ItemNo: Code[20]; begin ItemNo := '1908-S'; SalesLine.SetRange("Document Type", SalesHeader."Document Type"); SalesLine.SetRange("Document No.", SalesHeader."No."); if SalesLine.FindSet() then begin repeat begin PotLevyAmount := SalesLine.Amount * (5 / 100); end until SalesLine.Next() = 0; SalesLine.FindLast(); NewLineNo := SalesLine."Line No." 10000; NewSalesLine.Init(); NewSalesLine."Document Type" := SalesHeader."Document Type"; NewSalesLine."Document No." := SalesHeader."No."; NewSalesLine."Line No." := NewLineNo; NewSalesLine.Validate(Type, ItemType::Item); NewSalesLine.Validate("No.", ItemNo); if NewSalesLine.Insert(true) then begin NewSalesLine.Quantity := 1; NewSalesLine.Validate(Quantity); NewSalesLine.Amount := PotLevyAmount; NewSalesLine.Validate(Amount); NewSalesLine.Modify(true); end; end; end;
The issue is that, Sales line total values are not updated.
I highly appreciate your advice.
Thanks,
Nalin.