Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

How to create 100 purchase orders

Posted on by 75

Hi All,

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

Thanks & Regards,

Sams.

Categories:
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 70,059 Super User 2024 Season 2 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
    Nitin Verma 21,023 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
    Satish 75 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
    Inge M. Bruvik 32,744 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
    Satish 75 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
    Amit Baru 3,025 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
    Satish 75 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
    Amit Baru 3,025 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
    Nitin Verma 21,023 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
    Satish 75 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,556 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans