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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Update Sales Line field from item table

(0) ShareShare
ReportReport
Posted on by 1,165

Hi All,

I'm trying to update a new field in sales line table with description 2 from item table (when the order is released) ..I could get a header field on lines but not from item table. here's the code, need tips on how to link a third table such as Item or customer.

    EventSubscriberInstance = StaticAutomatic;
    [EventSubscriber(ObjectType::CodeunitCodeunit::"Release Sales Document", 'OnBeforeManualReleaseSalesDoc''', true, true)]
    local procedure MyProcedure(var SalesHeader: Record "Sales Header")
    var
        RecItem: Record Item;
        SalesLine: Record "Sales Line";

    begin
        SalesLine.RESET;
        SalesLine.SETRANGE("Document Type", SalesHeader."Document Type");
        SalesLine.SETRANGE("Document No.", SalesHeader."No.");
        SalesLine.SETRANGE("No.", RecItem."No.");
        IF SalesLine.FindSet() THEN
            REPEAT
                SalesLine.MyDescription := RecItem."Description 2";
                SalesLine.MODIFY(TRUE);
            UNTIL SalesLine.NEXT = 0;
    End;
I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    You need to do a GET on the item table. You haven’t satisfied any filters to identify which get you have the description 2 of.

    I would place an additional filter on the sales line for type::item or do a if recitem.get(SalesLine.”no.” Then before you set the SalesLine.description

  • Anita75 Profile Picture
    1,165 on at

    Thanks so much That worked as below - I have another question - is there any way to trigger this as a user enter each sales order line - say when selecting item code or line amount get updated?:

        EventSubscriberInstance = StaticAutomatic;

        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Sales Document", 'OnBeforeManualReleaseSalesDoc', '', true, true)]

        local procedure MyProcedure(var SalesHeader: Record "Sales Header")

        var

            RecItem: Record Item;

            SalesLine: Record "Sales Line";

        begin

            SalesLine.RESET;

            SalesLine.SETRANGE("Document Type", SalesHeader."Document Type");

            SalesLine.SETRANGE("Document No.", SalesHeader."No.");

            SalesLine.SetRange(Type::Item);

             IF SalesLine.FindSet() THEN

                REPEAT

                    If RecItem.get(SalesLine."No.") Then

                        SalesLine.MyDescription := RecItem."Description 2";

                    SalesLine.MODIFY(TRUE);

                UNTIL SalesLine.NEXT = 0;

        End;

  • Verified answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    Yes, you need to subscribe to the OnAfterValidate Event on the SalesLine Table for the No. field and then you can add your code or there is another event on the SalesLine called OnAfterCopyFromItem which you can use the same thing.

    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterCopyFromItem', '', false, false)]
        local procedure "Sales Line_OnAfterCopyFromItem"   (var SalesLine: Record "Sales Line"; Item: Record "Item"; CurrentFieldNo: Integer    )
        begin
            SalesLine.Description := Item."Description 2";
        end;

  • Anita75 Profile Picture
    1,165 on at

    Perfect that worked like a charm

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans