Posted Sales invoice Line Insert Field - which trigger

samantha73
Member Posts: 118
Hi All
I have created an UDF on posted sales invoice line table to record total shipped quantity on each line (from sales shipment line table). Trying to update this field via a code unit and not sure which code unit and trigger to use. Someone else mentioned to use OnAfterInitFromSalesLine
but could not find it on "Sales-Post" codeunit. This is on BC SaaS 17.5
I have created an UDF on posted sales invoice line table to record total shipped quantity on each line (from sales shipment line table). Trying to update this field via a code unit and not sure which code unit and trigger to use. Someone else mentioned to use OnAfterInitFromSalesLine
but could not find it on "Sales-Post" codeunit. This is on BC SaaS 17.5
0
Best Answer
-
First review your code. You are calling FINDSET on "salesline" but looping based on "SalesInvLine".
When populating custom fields, you are better off handing that in the OnbeforeInsert if possible. This eliminates the need for the second server round-trip. Reducing the number of server trips is a key factor in performance.There are no bugs - only undocumented features.0
Answers
-
Why you want to update shipped quantity from a codeunit?United Kingdom0
-
Actually two questions. One the immediate problem of updating a custom field before posting a sales invoice. Here we want to calculate back orders on sales invoice so we created a field to record all previously shipped quantities (Sum(shipment lines where order and line no = inv line ) and then we can use a transfer field from SO to get the original Qty. Second question is, irrespective of the current requirement, I'd like to know what triggers can be used to update line level fields in general0
-
it depends where you are update from and what point you want to do it. If you let us know what exactly you are trying to do?United Kingdom0
-
ok thanks . I'm looking to update a field with a value before posting invoice0
-
Ok its lockdown here so better to focus on code
gave it another crack..here's the trigger I found and the code..can someone see if this looks OK or any suggestions
[EventSubscriber(ObjectType::Codeunit, 80, 'OnAfterSalesInvLineInsert', '', false, false)]
local procedure OnafterInsertliney(var SalesInvLine: Record "Sales Invoice Line")
var
salesline: Record "Sales Line";
begin
salesline.Reset();
Salesline.SetRange("Document Type", salesline."Document Type"::Order);
salesline.SetRange(Type, salesline.Type::Item);
salesline.SetRange("Document No.", SalesInvLine."Order No.");
salesline.SetRange("Line No.", SalesInvLine."Order Line No.");
if salesline.FindSet() then
repeat
SalesInvLine."UDF-01" := salesline.Quantity;
SalesInvLine."UDF-02" := salesline."Quantity Shipped";
SalesInvLine.Modify();
until SalesInvLine.Next() = 0;
end;
0 -
First review your code. You are calling FINDSET on "salesline" but looping based on "SalesInvLine".
When populating custom fields, you are better off handing that in the OnbeforeInsert if possible. This eliminates the need for the second server round-trip. Reducing the number of server trips is a key factor in performance.There are no bugs - only undocumented features.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