Skip to main content

Notifications

Announcements

No record found.

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

How to Rename Purchase Order along with Purchase Line in Business Central?

Posted on by 80
Hello everyone,
I'm working on a job queue task where I need to ensure that when I rename a Purchase Header record, the corresponding Purchase Line records associated with it should also update accordingly. Could you please review and assist in refining this code?
 
dataitem(PurchaseLine; /Purchase Line/)
            {
                DataItemLink = /Document No./ = field(/No./);
                trigger OnPreDataItem()
                var
                    Rec_PurchaseHeader: Record /Purchase Header/;
                    Rec_PurchaseHeader1: Record /Purchase Header/;
                    Rec_PurchaseLine1: Record /Purchase Line/;
                    Rec_PurchaseLine: Record /Purchase Line/;
                begin
                    Rec_PurchaseHeader1.SetRange(/Document Type/, Rec_PurchaseHeader./Document Type/::Order);
                    Rec_PurchaseHeader1.SetRange(/No./, '106005');
                    if Rec_PurchaseHeader1.FINDSET then begin
                        if Rec_PurchaseHeader1./Document Type/ = Rec_PurchaseHeader1./Document Type/::Order then begin
                            Rec_PurchaseHeader1.Rename(Rec_PurchaseHeader./Document Type/::Order, '106022');
                            Rec_PurchaseLine1.SetFilter(/Document No./, '%1', '106001');
                            if Rec_PurchaseLine1.Findset then
                                Rec_PurchaseLine1.Rename(Rec_PurchaseLine./Document Type/::Order, 'PORD-1000', Rec_PurchaseLine./Line No./);
                        end;
                        if Rec_PurchaseHeader1./Document Type/ = Rec_PurchaseHeader1./Document Type/::Invoice then begin
                            Rec_PurchaseHeader1.Rename(Rec_PurchaseHeader./Document Type/::Invoice, '106021');
                        end;
                    end
                    else
                        ERROR('Purchase Header not found.');
                end;
            }
        }
Categories:
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    How to Rename Purchase Order along with Purchase Line in Business Central?
    Hi, I also want to know why you did this. . . . Does the order update its number every day?
    If you encounter the following error, it is because the standard has controls.
    For example


    Standard Control:
     

    So you also need to add the following code.
     
    But this will not modify the associated records. All associated records must be modified manually in the code. So this is not recommended.
     
     
    Thanks.
    ZHU
     
     
     
  • KasparsSemjonovs Profile Picture
    KasparsSemjonovs 3,934 Super User 2024 Season 2 on at
    How to Rename Purchase Order along with Purchase Line in Business Central?
    Not sure why You would need to change the PO number, but if it is a bulk update, so that all PO numbers need to be changed so they are starting from a specific number, maybe it would be easier to use the COPY DOCUMENT process and create so it copies the current document and deleted the old. But this would not work for partially processed orders.

    Otherwise You would need to look into the Rename function in other cards. Order documents don't have a built-in Rename function as far as I know, At least user cannot do it manually. But maybe someone who has more knowledge of development can give You more precise advice.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans