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...
Suggested answer

How to create 100 purchase orders

(0) ShareShare
ReportReport
Posted on by 2

Hi All,

       I want to create a 100 purchase orders with the same vendor and same item, can anyone help me

Thanks & Regards,

Sams.

  • Suggested answer
    YUN ZHU Profile Picture
    78,476 Super User 2025 Season 1 on at
    RE: How to create 100 purchase orders

    Hi, just adding an example for importing sales order, hope this helps.

    https://yzhums.com/4223/

    Thanks.

    ZHU

  • Suggested answer
    Nitin Verma Profile Picture
    21,361 Moderator on at
    RE: How to create 100 purchase orders

    Hi,

    Please change as per yellow marked.

         trigger OnAfterGetRecord()

               var

                   PurchaseHeader: Record "Purchase Header";

                   PurchaseLine: Record "Purchase Line";

                   i: Integer;

               begin

                   for i := 1 to 100 do begin

                       PurchaseHeader.init();

                       PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;

                       PurchaseHeader.validate("No.","");

                       PurchaseHeader.Validate("Buy-From Vendor No.", '20000');

                       PurchaseHeader."Posting Date" := WorkDate();

                       PurchaseHeader."Document Date" := PurchaseHeader."Posting Date";

                       PurchaseHeader."Due Date" := PurchaseHeader."Posting Date";

                       PurchaseHeader.Insert(true);

                       PurchaseLine.Init();

                       PurchaseLine."Document Type" := PurchaseHeader."Document Type";

                       PurchaseLine."Document No." := PurchaseHeader."No.";

                       PurchaseLine.SetRange("Document Type",PurchaseHeader."Document Type");

                       PurchaseLine.SetRange("Document No.",PurchaseHeader."No.");

                       PurchaseLine."Line No." := 10000;

                       PurchaseLine.Type:=   PurchaseLine.Type::Item;

                       PurchaseLine."No.":=   YourItemNo.Here.

                       PurchaseLine.Insert(true);

                   end;

               end;

  • Satish Profile Picture
    2 on at
    RE: How to create 100 purchase orders

    Hi All,

           I am Sharing my can you please guide me,

                 trigger OnAfterGetRecord()

               var

                   PurchaseHeader: Record "Purchase Header";

                   PurchaseLine: Record "Purchase Line";

                   i: Integer;

               begin

                   for i := 1 to 100 do begin

                       PurchaseHeader.init();

                       PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;

                       PurchaseHeader."No." := '';

                       PurchaseHeader.Validate("Buy-From Vendor No.", '20000');

                       PurchaseHeader."Posting Date" := WorkDate();

                       PurchaseHeader."Document Date" := PurchaseHeader."Posting Date";

                       PurchaseHeader."Due Date" := PurchaseHeader."Posting Date";

                       PurchaseHeader.Insert(true);

                       PurchaseLine.Init();

                       PurchaseLine."Document Type" := PurchaseHeader."Document Type";

                       PurchaseLine."Document No." := PurchaseHeader."No.";

                       PurchaseLine.SetRange("Document Type",PurchaseHeader."Document Type");

                       PurchaseLine.SetRange("Document No.",PurchaseHeader."No.");

                       PurchaseLine."Line No." := 10000;

                       PurchaseLine.Insert(true);

                   end;

               end;

    Thanks & Regards,

    Sams

  • Suggested answer
    Inge M. Bruvik Profile Picture
    997 Moderator on at
    RE: How to create 100 purchase orders

    It looks like you are trying to modify the System Id in your code. And that is not allowed.

    Maybe you can share your code so we can give you more efficient help?

  • Satish Profile Picture
    2 on at
    RE: How to create 100 purchase orders

    Hi All,

            I have set the Vednor posting group and all, but I am getting this error, can anyone tell me what is this error and how to solve this error.

               pastedimage1663477136129v1.png

  • Suggested answer
    Amit Baru Profile Picture
    3,027 on at
    RE: How to create 100 purchase orders

    Hi,

    Pls Assign Vendor Posting Group in Vendor. My given code is correct. This is setup issue.

  • Satish Profile Picture
    2 on at
    RE: How to create 100 purchase orders

    Hi All,

          I am using this code for creation of 100 purchase orders in a report,

              trigger OnAfterGetRecord()

               var

                   PurchaseHeader: Record "Purchase Header";

                   PurchaseLine: Record "Purchase Line";

                   Vendor: Record Vendor;

                   GetVendorNo: code[20];

                   GetLocation: code[20];

                   DocumentNo: Code[20];

                   i: Integer;

               begin

                   for i := 1 to 100 do begin

                       PurchaseHeader.init();

                       PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;

                       PurchaseHeader."No." := '20000';

                       // PurchaseHeader.Insert(True);

                       PurchaseHeader.Validate("Buy-From Vendor No.", Vendor."No.");

                       PurchaseHeader.Validate("Posting Date", Workdate);

                       PurchaseHeader.Validate("Location Code", GetLocation);

                       PurchaseHeader."Vendor Posting Group" := Vendor."Vendor Posting Group";

                       // DocumentNo := PurchaseHeader."No.";

                       if not PurchaseHeader.Insert() then

                           PurchaseHeader.Modify;

                       PurchaseLine.Init();

                       PurchaseLine."Document Type" := PurchaseLine."Document Type"::Order;

                       PurchaseLine."Document No." := PurchaseHeader."No.";

                       PurchaseLine."Line No." := 10000;

                       PurchaseLine.Insert();

                   end;

                       But I am getting an error I am attaching the error, can anyone help me.

    pastedimage1663412537397v2.png

    Thanks & Regards,

    Sams

  • Suggested answer
    Amit Baru Profile Picture
    3,027 on at
    RE: How to create 100 purchase orders

    Hi,

    Use the below code for reference.

    report 50230 MyReport
    {
        UsageCategory = ReportsAndAnalysis;
        ApplicationArea = All;
        ProcessingOnly = Yes;

        dataset
        {
            dataitem(DataItemName; Integer)
            {
                //SourceTable =
                trigger OnAfterGetRecord()
                var
                    PurchaseHeader: Record "Purchase Header";
                    PurchaseLine: Record "Purchase Line";
                    GetVendorNo: code[20];
                    GetLocation: code[20];
                begin
                    for i := 1 to 100 do begin
                        PurchaseHeader.init;
                        PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;
                        PurchaseHeader."No" := '';
                        PurchaseHeader.Insert(True);
                        PurchaseHeader.Validate(Buy - From Vendor No.",GetVendor);
                        PurchaseHeader.Validate("Posting Date", Workdate);
                        PurchaseHeader.Validate("Location Code", GetLocation);
                        DocumentNo := PurchaseHeader."No";
                        if PurchaseHeader.Modify then begin
                            PurchaseLine.Init;
                            PurchaseLine."Document Type" := PurchaseLine."Document Type"::Order;
                            PurchaseLine."Document No." := DocumentNo;
                            PurchaseLine."Line No." += 10000;
                            PurchaseLine.Insert;
                        end;

                    end;
                end;
            }
        }

        requestpage
        {
            layout
            {
                area(Content)
                {
                    group(GroupName)
                    {
                        field(Name; GetVendorNo)
                        {
                            ApplicationArea = All;

                        }
                    }
                }
            }

        }

        var
            myInt: Integer;
    }
    Regards
    Amit Sharma
  • Suggested answer
    Nitin Verma Profile Picture
    21,361 Moderator on at
    RE: How to create 100 purchase orders

    Hi,

    In that case you can create a CSV file with putting your Header and Line data in it, and then import that CSV file directly from Report using CSV import.

    You can go with XML port creation

    docs.microsoft.com/.../devenv-xmlport-object

    Import CSV file using XML port

    www.hougaard.com/.../

    divyeshchittenavbc.wordpress.com/.../

  • Satish Profile Picture
    2 on at
    RE: How to create 100 purchase orders

    Hi Nithin,

                I have to create a 100 purchase orders with the one vendor and one item only, this has to be done by the reports, but my question is how to create the purchase order.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,688 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,643 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans