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
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.
Can you please show in code what changes needed to be done and
How can I attach CSV file in my mail.
Thankyou.
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156