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
Hello,
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.
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.
What kind of error are you getting in your report?
Maybe you should look into using the CSV buffer code unit.
Hello,
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.
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.
And hopefully Erik's video below will give you some hints as well.
https://www.youtube.com/watch?v=zrJXze8zwT0
Thanks.
ZHU
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,232 Super User 2024 Season 2
Martin Dráb 230,064 Most Valuable Professional
nmaenpaa 101,156