Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Business Central

Posted on by 200

0714.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)

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

2)Unable to create CSV and get data as shown in image

codeunit 50129 " Orders packed by packer"

{

    procedure shipmentorder()

    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', '');

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

      TotalUserOrder := rec_postedsales.Count;

 if rec_postedsales.FindSet() then

            repeat

                if postingDate <> rec_postedsales."Posting Date" then begin

                    rec_postedsales2.SetRange("Posting Date", rec_postedsales."Posting Date")

                    Message('Total Orders %1 on Posting Date %2', rec_postedsales2.Count, rec_postedsales2."Posting Date");

                end;

                postingDate := rec_postedsales."Posting Date";

            until rec_postedsales.Next() < 1;

                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";//table 

    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;

   rec_orderspack: Record "Orders packed by packer";//table 

begin

        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

    Hello,

    1777.monthly-ss.png

    As shown in the image, I needed Username and numbers from 1 to 31 as header(in csv) and it's (each day for one month from today), how can we take numeric values while creating a report, as it's showing some error. I needed each day sales order count what can be done.

    Please do help

    Thankyou.

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

    packing-orders.png

    I am getting same user many times I don't want repeated User 

    I am not able to insert numeric values as header in report.

    And also not getting proper count of sales order in posted sales shipment in CSV.

    procedure orderpacked(

        va

            rec_postedsales: Record "Sales Shipment Header"

            rec_postedsales2: Record "Sales Shipment Header"

            rec_User: Record User

            user: text

            TotalUserOrder: Integer

            postingDate: Date

            ord: Text

            packeorders: Integer

            rec_orderspack: Record "Orders packed by packer"

        beg

            rec_postedsales.Reset()

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

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

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

            TotalUserOrder := rec_postedsales.Count

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

            rec_postedsales.SetCurrentKey("Posting Date"

            rec_postedsales.Ascending(true)

            if rec_postedsales.FindFirst() th

                repea

                    if postingDate <> rec_postedsales."Posting Date" then beg

                        rec_postedsales2.SetRange("Posting Date", rec_postedsales."Posting Date"

                        packeorders := 0

                        packeorders := rec_postedsales2.Count

                        Message('Total Orders %1 on Posting Date %2', rec_postedsales2.Count, rec_postedsales."Posting Date")

                        //InsertIntoTable(rec_postedsales, rec_postedsales2)

                        if rec_postedsales.Count > 0 then be

                            rec_orderspack.Init(

                            rec_orderspack.No := CreateGuid()

                            rec_orderspack.Username := rec_postedsales."User ID"

                            rec_orderspack.One := packeorders

                            rec_orderspack.Two := packeorders

                            rec_orderspack.Three := packeorders

                            rec_orderspack.Four := packeorders

                            rec_orderspack.Five := packeorders

                            rec_orderspack.Six := packeorders

                            rec_orderspack.Seven := packeorders

                            rec_orderspack.Eight := packeorders

                            rec_orderspack.Nine := packeorders

                            rec_orderspack.Ten := packeorders

                            rec_orderspack.Insert

                        end

                    end

                // postingDate := rec_postedsales."Posting Date

                until rec_postedsales.Next() = 

        end;

    0;";;;();;;;;;;;;;;;);gin;;;;);inten;);;;;;;;in;;;;;;;;;r)

                until rec_postedsales.Next() = 0;

        end;           

    Is anything more to update in code please help 

    Thankyou.

  • Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Business Central

    What kind of error are you getting in your report?

    Maybe you should look into using the CSV buffer code unit.

    www.youtube.com/watch

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

    Hello,

    8473.monthly-ss.png

    As shown in the image, I needed Username and numbers from 1 to 31 as header(in csv) and it's (each day for one month from today), how can we take numeric values while creating a report, as it's showing some error.

    Please do suggest

    Thankyou.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,378 Super User 2024 Season 2 on at
    RE: Business Central

    I think there is something wrong with the way you think about it.
    You should create a report and use it as Email Body instead of hard-coding a table in the program.

    pastedimage1678060895478v1.png

    And hopefully Erik's video below will give you some hints as well.

    https://www.youtube.com/watch?v=zrJXze8zwT0

    Thanks.

    ZHU

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans