Skip to main content
Business Central forum
Answered

creating a purchase order with multiple items

editSubscribe (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.
Categories:
  • 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 20,984 Super User 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 20,984 Super User 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,025 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

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans