xRec and Rec have same value in sales line OnAfterModifyEvent (automated tests)

markcle
Member Posts: 65
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
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
-
It's confusing but that's how it works, xRec acts differently based on where/how the code is called. Check out this link for more details...
https://docs.microsoft.com/en-us/dynamics-nav/xrec-and-currfieldno1 -
Thanks!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions