Skip to main content

Notifications

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

Business Central

Posted on by 200

1440.monthly-ss.png

As show in the image wanted to display this in CSV form in mail need usernames from user table and it's total sales order which is in posted sales shipment and also how many sales order is posted each day (for one month back from today)

This is my code, my not getting the sales order for each day.

Codeunit 50129 " Orders packed by packer"

{

    var

        cdu_CommonHelper: Codeunit "Common Helper";

    procedure orderpacked()

    var

        rec_postedsales: Record "Sales Shipment Header";

        rec_postedsales2: Record "Sales Shipment Header";

        rec_User: Record User;

        user: text;

        TotalUserOrder: Integer;

        postingDate: Date;

    begin

        rec_postedsales.Reset();

        rec_postedsales.SetFilter("User ID", '<>%1', '');

        rec_postedsales.SetFilter("Order No.", '<>%1', '');

        TotalUserOrder := rec_postedsales.Count;

        if rec_postedsales.FindSet() then

            repeat

                rec_postedsales.SetCurrentKey("Posting Date");

                rec_postedsales.Ascending(true);

                rec_postedsales.SetRange("Posting Date", Today -31, Today );

                Message('Total user''s orders:%1', TotalUserOrder);

                InsertIntoTable(rec_postedsales);

            until rec_postedsales.Next() < 1;

    end;

    procedure InsertIntoTable(rec_postedsales: Record "Sales Shipment Header")

    var

        rec_orderspack: Record "Orders packed by packer";

    begin

        rec_orderspack.Init();

        rec_orderspack.No := CreateGuid();

        rec_orderspack.Username := rec_postedsales."User ID";

        rec_orderspack.Insert();

    end;

    procedure SendEmail()

    var

        cdu_EmailMessage: Codeunit "Email Message";

        cdu_Email: Codeunit Email;

        enum_Alerts: Enum Alerts;

        Subject: Text;

        Body: Text;

        //enum_RecipientType: Enum "Email Recipient Type";

        // ReportIdString: Text;

        //ReportId: Integer;

        rec_orderspack: Record "Orders packed by packer";

    begin

        //ToRecipients := 'dividutt.namboodiri@aressindia.net'; //Graham from: Harts of Stur

        Subject := 'This month orders packed by packer';

        Body += '<style>table, th, td {border:1px solid #999999;border-collapse: collapse;text-align:left;}th{padding:5px;background:#ccc;}td{padding:5px;}</style>';

        Body += '<table border="1">';

        Body += '<tr>';

        Body += '<th>Username</th>';

        Body += '<th>1</th>';//day one is it correct way?

        Body += '<th>2</th>'; //day two

Body += '<th>3</th>'; 

Body += '<th>4</th>';

Body += '<th>5</th>';

Body += '<th>6</th>';

Body += '<th>7</th>';

Body += '<th>8</th>';

Body += '<th>9</th>';

Body += '<th>10</th>';

        Body += '</tr>';

        Body += '</tr>';

        if rec_orderspack.FindSet() then

            repeat

                Body += '<tr>';

                Body += STRSUBSTNO('<td>%1</td>', rec_orderspack.Username);

                Body += '</tr>';

            until rec_orderspack.Next() = 0;

        Body += '</table>';

        Body += '<br><br>Kind Regards,<br><br>Business Central';

        cdu_EmailMessage.Create(cdu_CommonHelper.EmailSetup(enum_Alerts::" Orders packed by packer"), Subject, Body, true);

        if rec_orderspack.Count > 0 then begin

            cdu_Email.Send(cdu_EmailMessage);

            rec_orderspack.DeleteAll();

        end;

    end;

}

So can you please help in this code..

I want to get output as shown in image i e count of sales order which is in post sales shipment of each today (from -31 today)

Please do help in this 

Thankyou 

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    I needed to get all the sales order which is in posted sales shipment in CSV file and that file show order count for each day(from today to one month back)how it can done in Al code

    Please do help

    Thankyou.

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    Can you please show in code what changes needed to be done and

    How can I attach CSV file in my mail.

    Thankyou.

  • Verified answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Business Central

    hi

    Based on the code you provided, it seems that the issue is that you are not actually filtering the sales shipments by the posting date in the loop where you are inserting them into the table.

    You should move the filtering code outside of the loop where you are finding the sales shipments and add it before you call the FindSet() method. Additionally, you need to make sure that you are only finding sales shipments that have been posted.

    DAniele

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans