web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Codeunit not working

(0) ShareShare
ReportReport
Posted on by 92

I have created an extension of the table "Sales line", in which I have created a field "Shipped Not Inv. No VAT", which should be the result of the multiplication of two existing fields in the table, "Qty. Shipped Not Invoiced" * "Unit price", this in each line.

To perform this operation, I made a codeunit, following this example: 

https://community.dynamics.com/business/f/dynamics-365-business-central-forum/300617/add-dynamically-calculated-field-to-sales-document-lines

But nothing happens, should I add something else?

Here is my code:

pastedimage1632505659812v1.png

codeunit 52122 ShipNotInvNoVATPub
{
    trigger OnRun()
    begin

    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterValidate(var r: Record "Sales Line")
    begin
    end;
}

codeunit 52123 ShipNInvNoVATSub
{
    trigger OnRun()
    begin

    end;

    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'Unit Price', false, false)]
    local procedure UnitPriceChange(var Rec: Record "Sales Line")
    begin
        Rec."Shipped Not Inv. No VAT" := Rec."Unit Price" * Rec."Qty. Shipped Not Invd. (Base)";
    end;

    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'Qty. Shipped Not Invd. (Base)', false, false)]
    local procedure QtyChange(var Rec: Record "Sales Line")
    begin
        Rec."Shipped Not Inv. No VAT" := Rec."Unit Price" * Rec."Qty. Shipped Not Invd. (Base)";
    end;


}

  • Suggested answer
    JAngle Profile Picture
    161 on at

    On the sales header you have these two fields:

    field(300; "Amt. Ship. Not Inv. (LCY)"; Decimal)

           {

               CalcFormula = Sum ("Sales Line"."Shipped Not Invoiced (LCY)" WHERE("Document Type" = FIELD("Document Type"),

                                                                                  "Document No." = FIELD("No.")));

               Caption = 'Amount Shipped Not Invoiced (LCY) Incl. VAT';

               Editable = false;

               FieldClass = FlowField;

           }

           field(301; "Amt. Ship. Not Inv. (LCY) Base"; Decimal)

           {

               CalcFormula = Sum ("Sales Line"."Shipped Not Inv. (LCY) No VAT" WHERE("Document Type" = FIELD("Document Type"),

                                                                                     "Document No." = FIELD("No.")));

               Caption = 'Amount Shipped Not Invoiced (LCY)';

               Editable = false;

               FieldClass = FlowField;

    Difference being you want yours in the document currency? I’ll question the motive of the change before the quality of the code

  • BchM Profile Picture
    92 on at

    Yes, I want to have the fields "Amt. Ship. Not Inv." and "Amt. Ship. Not Inv. Base" (Without LCY).

    I have already created the field "Amt. Ship. Not Inv.", It was simple because in the Sales Line table there is already the field "Shipped Not Invoiced"

    pastedimage1632518213498v1.png

    But I could not create the field "Amt. Ship. Not Inv. Base", because in Sales Line there is no field "Shipped Not Inv. No VAT", and that is what I am trying to do

  • Suggested answer
    JAngle Profile Picture
    161 on at

    So would it make sense to use the standard sales line field "Shipped Not Inv. (LCY) No VAT" and then get the currency factor from the Sales Header to then convert the value? OnAfterValidate of the currency code you could update the field.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 569 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 375 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 228 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans