Hello,
am working on a report to generate dates of the month...eg from 1st to 31st for jan,,,I have been given an idea of using dataItem but not yet got it
Any code I can read through?
Hello,
am working on a report to generate dates of the month...eg from 1st to 31st for jan,,,I have been given an idea of using dataItem but not yet got it
Any code I can read through?
Hello,
You can use the virtual table "Date". Below is a sample that iterates through january in a codeunit, but you can also specify "Date" as a dataitem in a report. Remember to filter on "Period Type". Here, if you want individual days, then filter it on Date:
MyDate.setrange("Period Type", MyDate."Period Type"::Date);
If you wanted the months of the year, you would filter on Month.
In the sample below, run Business Central with MyServer:8080/.../ then click action "Create Dates", (or run the codeunit somehow else).
Hope this gets you some ideas.
Sample code:
codeunit 50100 GenerateDates
{
trigger OnRun()
begin
CreateDates(20220101D, 20220131D);
end;
local procedure CreateDates(FromDate: Date; ToDate: date)
var
begin
MyDate.setrange("Period Type", MyDate."Period Type"::Date);
MyDate.setrange("Period Start", FromDate, ToDate);
if MyDate.FindSet() then
repeat
if not Confirm(format(MyDate."Period Start")) then error('Cancelled.');
until MyDate.Next() = 0;
end;
var
MyDate: Record Date;
}
page 50101 RunMyCodeunit
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Administration;
actions
{
area(Processing)
{
action(CreateDates)
{
Caption = 'Create Dates';
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
ApplicationArea = All;
trigger OnAction()
begin
codeunit.run(Codeunit::GenerateDates);
end;
}
}
}
var
myInt: Integer;
}
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,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156