We are using the Microsoft Sales Test Library to create sales lines. We have an extension where we need to log certain changes to sales line fields under certain conditions (change log won't work for what we need)
We have a subscription on sales lines that works fine when we use the web client with keyboard and mouse (BC2020 wave 1)
[EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterModifyEvent', '', true, true)]
local procedure LogEntrySalesLine(var Rec: Record "Sales Line"; var xRec: Record "Sales Line")
var
CU1: Codeunit "My CodeUnit";
begin
if Rec.IsTemporary then exit;
if (Rec.Quantity = 0) and (xRec.Quantity = 0) then exit; // This is always true when run from tests
if Rec.Type = Rec.Type::Item then
CU1.LogSalesLines(Rec, xRec);
end;
We create a sales line using SalesLibrary.CreateSalesLine and then do SalesLine.Validate(Quantity, 10) and SalesLine.Modify(true). In the event subscription, Rec and xRec have the same values for all fields
We then tried doing it without using the Microsoft Test Libraries.
SalesLine.Init();
SalesLine.Validate("Document Type", SalesHeader."Document Type");
SalesLine.Validate("Document No.", SalesHeader."No.");
RecRef.GetTable(SalesLine);
SalesLine.Validate("Line No.", LibraryUtility.GetNewLineNo(RecRef, SalesLine.FieldNo("Line No.")));
SalesLine.Insert(true);
SalesLine.Validate(Type, SalesLine.Type::Item);
SalesLine.Validate("No.", Item."No.");
SalesLine.Validate("Shipment Date", SalesHeader."Shipment Date");
if Qty <> 0 then
SalesLine.Validate(Quantity, Qty);
SalesLine.Modify(true);
Same problem
The only way we can get the test execute the code in the subscription and pass the assertions by using a TestPage:
var
SalesOrderSubform: TestPage "Sales Order Subform";
Begin
SalesOrderSubform.OpenEdit();
SalesOrderSubform.GoToKey(SalesDocTypeEnum::"Order", SalesHeader."No.", SalesLineNo);
SalesOrderSubform.Quantity.SetValue(10);
SalesOrderSubform.OK.Invoke();
Anyone got any ideas?
Thanks
Mark
0
Answers
https://docs.microsoft.com/en-us/dynamics-nav/xrec-and-currfieldno