Skip to main content

Notifications

Announcements

No record found.

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

creating a purchase order with multiple items

(0) ShareShare
ReportReport
Posted on by 130

Hi ALL,

            I am creating a purchase order through AL code using multiple items, in a report but it is coming like this, 

pastedimage1664427859894v1.png

Can anyone help me please, I am sharing my code how to I am creating the purchase order.

report 50408 "Purchase Order MultipleItems"
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    ProcessingOnly = true;

    dataset
    {
     

        dataitem(Integer; Integer)
        {
            trigger OnAfterGetRecord()
            var

                PurchaseHeader: Record "Purchase Header";
                PurchaseLine: Record "Purchase Line";
                Vendor: Record Vendor;
                i: Integer;
            begin
                // for i := 0 to 1 do begin
                if Vendor."No." = '' then
                    CurrReport.Skip();
                PurchaseHeader.init();
                PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;
                PurchaseHeader.Validate("No.", '');
                PurchaseHeader.Insert(true);
                PurchaseHeader.Validate("Buy-From Vendor No.", '20000');
                PurchaseHeader."Posting Date" := WorkDate();
                PurchaseHeader."Document Date" := PurchaseHeader."Posting Date";
                PurchaseHeader."Due Date" := PurchaseHeader."Posting Date";
                PurchaseHeader.Modify();
                PurchaseLine.Init();
                PurchaseLine."Document Type" := PurchaseHeader."Document Type";
                PurchaseLine."Document No." := PurchaseHeader."No.";
                PurchaseLine."Line No." := 10000;
                PurchaseLine.Insert(true);
                PurchaseLine.Type := PurchaseLine.Type::Item;
                PurchaseLine."No." := '1896-S';
                PurchaseLine.Modify();
                PurchaseLine.Init();
                PurchaseLine."Document Type" := PurchaseHeader."Document Type";
                PurchaseLine."Document No." := PurchaseHeader."No.";
                PurchaseLine."Line No." += 10000;
                PurchaseLine.Insert(true);
                PurchaseLine.Type := PurchaseLine.Type::Item;
                PurchaseLine."No." := '1900-S';
                PurchaseLine.Modify();

            end;
            // end;
        }
    }

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

                    // }
                }

            }
        }
        actions
        {
            area(processing)
            {
                action(ActionName)
                {
                    ApplicationArea = All;

                }
            }
        }
    }
}
Thanks & Regards,
P V Sarath.
  • P V Sarath Profile Picture
    P V Sarath 130 on at
    RE: creating a purchase order with multiple items

    Hi Nitin,

                 Thanks for your help.

    Thanks & Regards.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: creating a purchase order with multiple items

    Try this one

    report 51458 "Purchase Order MultipleItems"
    {
        UsageCategory = ReportsAndAnalysis;
        ApplicationArea = All;
        ProcessingOnly = true;

        trigger OnPostReport()
        var

            PurchaseHeader: Record "Purchase Header";
            PurchaseLine: Record "Purchase Line";
            Vendor: Record Vendor;
            i: Integer;
        begin
            // for i := 0 to 1 do begin
            PurchaseHeader.init();
            PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;
            PurchaseHeader.Validate("No.", '');
            PurchaseHeader.Insert(true);
            PurchaseHeader.Validate("Buy-From Vendor No.", '20000');
            PurchaseHeader."Posting Date" := WorkDate();
            PurchaseHeader."Document Date" := PurchaseHeader."Posting Date";
            PurchaseHeader."Due Date" := PurchaseHeader."Posting Date";
            PurchaseHeader.Modify();
            PurchaseLine.Init();
            PurchaseLine."Document Type" := PurchaseHeader."Document Type";
            PurchaseLine."Document No." := PurchaseHeader."No.";
            PurchaseLine."Line No." := 10000;
            PurchaseLine.Insert(true);
            PurchaseLine.Type := PurchaseLine.Type::Item;
            PurchaseLine."No." := '1896-S';
            PurchaseLine.Modify();
            PurchaseLine.Init();
            PurchaseLine."Document Type" := PurchaseHeader."Document Type";
            PurchaseLine."Document No." := PurchaseHeader."No.";
            PurchaseLine."Line No." += 10000;
            PurchaseLine.Insert(true);
            PurchaseLine.Type := PurchaseLine.Type::Item;
            PurchaseLine."No." := '1900-S';
            PurchaseLine.Modify();

        end;
       
    }
  • P V Sarath Profile Picture
    P V Sarath 130 on at
    RE: creating a purchase order with multiple items

    Hi Nitin,

                 I am trying in your way but it is not working, in the debugger also it is not catching the report, can you suggest me another way,

    Thanks & Regards

    P V Sarath.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: creating a purchase order with multiple items

    Hi,

    You can go with the below code.

    report 51458 "Purchase Order MultipleItems"
    {
        UsageCategory = ReportsAndAnalysis;
        ApplicationArea = All;
        ProcessingOnly = true;

        trigger OnPostReport()
        var

            PurchaseHeader: Record "Purchase Header";
            PurchaseLine: Record "Purchase Line";
            Vendor: Record Vendor;
            i: Integer;
        begin
            // for i := 0 to 1 do begin
            if Vendor."No." = '' then
                CurrReport.Skip();
            PurchaseHeader.init();
            PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;
            PurchaseHeader.Validate("No.", '');
            PurchaseHeader.Insert(true);
            PurchaseHeader.Validate("Buy-From Vendor No.", '20000');
            PurchaseHeader."Posting Date" := WorkDate();
            PurchaseHeader."Document Date" := PurchaseHeader."Posting Date";
            PurchaseHeader."Due Date" := PurchaseHeader."Posting Date";
            PurchaseHeader.Modify();
            PurchaseLine.Init();
            PurchaseLine."Document Type" := PurchaseHeader."Document Type";
            PurchaseLine."Document No." := PurchaseHeader."No.";
            PurchaseLine."Line No." := 10000;
            PurchaseLine.Insert(true);
            PurchaseLine.Type := PurchaseLine.Type::Item;
            PurchaseLine."No." := '1896-S';
            PurchaseLine.Modify();
            PurchaseLine.Init();
            PurchaseLine."Document Type" := PurchaseHeader."Document Type";
            PurchaseLine."Document No." := PurchaseHeader."No.";
            PurchaseLine."Line No." += 10000;
            PurchaseLine.Insert(true);
            PurchaseLine.Type := PurchaseLine.Type::Item;
            PurchaseLine."No." := '1900-S';
            PurchaseLine.Modify();

        end;
       
    }
  • Suggested answer
    Amit Baru Profile Picture
    Amit Baru 3,027 on at
    RE: creating a purchase order with multiple items

    hi,

    Pls apply filter on Integer onpredataitem

    Setrange(Number,1);

    In your case Integer is running in infinite loop.

    Regards

    Amit Sharma

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans