Hello Everyone.
Have you ever encountered a step that takes a long time to execute when running Business Central customized features?
It is recommended to add a progress indicator to display the progress. You can run it in the foreground to have a better clarity of it and even close it while it is running.
So how to do it.
I will give two type of examples: Action in page and Report.
Actions:
Example 01:
action(ProgressIndicator)
{
Caption = 'Progress Indicator';
ApplicationArea = All;
Image = Calculate;
trigger OnAction()
var
Progress: Dialog;
Counter: Integer;
Text000: Label 'Counting to 100 ------ #1';
begin
Counter := 0;
Progress.OPEN(Text000, Counter);
REPEAT
// Do some processing.
Counter := Counter + 1;
Progress.UPDATE(); // Update the field in the dialog.
SLEEP(50);
UNTIL Counter = 100;
Progress.CLOSE()
end;
}
Example 02:
action(ProgressIndicator)
{
Caption = 'Progress Indicator';
ApplicationArea = All;
Image = Calculate;
trigger OnAction()
var
Progress: Dialog;
Counter: Integer;
ProgressMsg: Label 'Processing......#1######################\';
begin
Clear(Counter);
if not GuiAllowed then
exit;
Progress.Open(ProgressMsg);
// Do some processing
for Counter := 1 to 100 do begin
Progress.Update(1, Counter);// Update the field in the dialog.
Sleep(50);
end;
Progress.Close();
end;
}
Example 03:
action(ProgressIndicator)
{
Caption = 'Progress Indicator';
ApplicationArea = All;
Image = Calculate;
trigger OnAction()
var
Progress: Dialog;
Counter: Integer;
ProgressMsg: Label 'Progress from 0 to 9999 #1#####';
begin
Counter := 0;
Progress.OPEN(ProgressMsg, Counter);
REPEAT
// Do some processing.
Counter := Counter + 1;
Progress.UPDATE(); // Update the field in the dialog.
SLEEP(50);
UNTIL Counter = 9999;
Progress.CLOSE()
end;
}
If it takes a long time to complete, you can click “Cancel” to stop it.
PS:
In Business Central 14 and previous versions, you can use the “@1” to display the progress bar to show the percentage in windows client.
Text constant name | Constant value |
---|---|
Text000 | Progress from 0 to 9999 @1@@@@@ |
Report:
Example 01:
report 50100 ProgressIndicator
{
Caption = 'Progress Indicator';
UsageCategory = Administration;
ApplicationArea = All;
ProcessingOnly = true;
dataset
{
}
trigger OnPreReport()
var
begin
Clear(Counter);
if not GuiAllowed then
exit;
Progress.Open(ProgressMsg);
end;
trigger OnPostReport()
var
begin
// Do some processing
for Counter := 1 to 100 do begin
Progress.Update(1, Counter);// Update the field in the dialog.
Sleep(50);
end;
Progress.CLOSE()
end;
var
Progress: Dialog;
Counter: Integer;
ProgressMsg: Label 'Processing......#1######################\';
}
Reference link:
Open Method
Hope this will help.
Thanks.
コメント