Posted Sales invoice Line Insert Field - which trigger

samantha73samantha73 Member Posts: 96
edited 2021-05-28 in NAV Three Tier
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

Best Answer

  • bbrownbbrown Member Posts: 3,268
    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.

Answers

  • Developer101Developer101 Member Posts: 528
    Why you want to update shipped quantity from a codeunit?
    United Kingdom
  • samantha73samantha73 Member Posts: 96
    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 general
  • Developer101Developer101 Member Posts: 528
    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 Kingdom
  • samantha73samantha73 Member Posts: 96
    ok thanks . I'm looking to update a field with a value before posting invoice
  • samantha73samantha73 Member Posts: 96
    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;
  • bbrownbbrown Member Posts: 3,268
    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.
Sign In or Register to comment.