web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Business Central

(0) ShareShare
ReportReport
Posted on by 208

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 

  • Verified answer
    DAnny3211 Profile Picture
    11,427 Super User 2026 Season 1 on at

    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

  • Dividutt Profile Picture
    208 on at

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

    How can I attach CSV file in my mail.

    Thankyou.

  • Dividutt Profile Picture
    208 on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 741 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 514 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 336 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans