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

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

(1) ShareShare
ReportReport
Posted on by 208
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;
            }
        }
I have the same question (0)
  • KasparsSemjonovs Profile Picture
    4,764 Super User 2025 Season 2 on at
    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.
  • Verified answer
    YUN ZHU Profile Picture
    95,381 Super User 2025 Season 2 on at
    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
     
     
     

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,990

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,576 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,028 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans