Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Update Sales Line field from item table

Posted on by 1,159

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;
  • Anita75 Profile Picture
    Anita75 1,159 on at
    RE: Update Sales Line field from item table

    Perfect that worked like a charm

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Update Sales Line field from item table

    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
    Anita75 1,159 on at
    RE: Update Sales Line field from item table

    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;

  • Suggested answer
    JAngle Profile Picture
    JAngle 33,159 on at
    RE: Update Sales Line field from item table

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans