Enhancing User Experience with a Progress Indicator in Microsoft Dynamics 365 Business Central
Enhancing User Experience with a Progress Indicator in Microsoft Dynamics 365 Business Central
When developing applications in Microsoft Dynamics 365 Business Central, providing feedback to users during long-running tasks is essential to maintain a smooth and responsive experience. A great way to achieve this is by using a progress indicator—a visual cue that informs the user about the status of ongoing processes.
In this blog, we’ll walk you through an implementation of a progress indicator for processing records in Business Central, focusing on a sample code that updates a custom progress message as it processes each customer record. We’ll also explore how to provide real-time feedback during long operations and how this technique improves the user experience.
The Problem
Imagine you are processing a large number of customer records, updating fields, or performing other resource-intensive tasks. Without any indication of progress, the user might assume the system has frozen or is not working. This can lead to frustration or unnecessary retries.
The solution? A progress indicator!
The Solution: Creating a Progress Indicator
We’ll start by reviewing the key elements of a Business Central page that integrates a progress indicator. Here’s how to implement a simple progress dialog for processing customer records.
Step 1: Create a New Page with Progress Indicator
Let’s assume you want to create a page where an admin user can start processing customer records with a progress indicator. The page will have a button (action) that, when clicked, simulates the processing of each customer, updating the user on the status along the way.
Below is the AL code for a new page, with an action that triggers a dialog showing the processing progress:
page 50206 "Progress_Indicator_Page"
{
Caption = 'Progress Indicator';
PageType = Card;
ApplicationArea = All;
UsageCategory = Administration;
actions
{
area(Processing)
{
action(Progress_Indicator_Action)
{
Caption = 'Process Customers';
ApplicationArea = All;
Image = Process;
trigger OnAction()
var
Dialog: Dialog;
Counter: Integer;
TotalCount: Integer;
CustomerRec: Record Customer;
ProgressMessage: Text[100];
begin
// Initialize counters
TotalCount := CustomerRec.Count;
Counter := 0;
// Open the dialog with an initial message
Dialog.Open('Processing customers...');
// Simulate processing of customers
if CustomerRec.FindSet() then begin
repeat
// Simulate some processing logic (e.g., update a field)
CustomerRec.Name := CustomerRec.Name + ' - Processed';
CustomerRec.Modify();
// Prepare a new progress message
Counter := Counter + 1;
ProgressMessage := 'Processing customer ' + Format(Counter) + ' of ' + Format(TotalCount);
// Close and reopen the dialog with the updated message
Dialog.Close();
Dialog.Open(ProgressMessage); // Update message in dialog
// Optional: Simulate a delay for processing time
Sleep(50); // Simulate time-consuming task
until CustomerRec.Next() = 0;
end;
// Close the dialog once processing is complete
Dialog.Close();
Message('Processing complete!');
end;
}
}
}
}
Step 2: Understanding the Code
Let’s break down the key components of the code:
Page Definition:
This is a simple page (with a page type of Card) titled "Progress Indicator".
The page includes an action under the Processing area, which, when triggered, starts processing the customer records.
Dialog Setup:
The Dialog object is used to open a dialog box with a progress message.
Initially, a generic message "Processing customers..." is displayed.
Progress Simulation:
The code retrieves a set of customer records using the FindSet method.
As each customer is processed (in this example, just modifying their name), the counter is incremented and the progress message is updated.
User Feedback:
After each modification, the dialog is closed and reopened with the updated progress message (e.g., "Processing customer 1 of 100").
A Sleep function is used to simulate a time-consuming operation, giving the illusion of progress.
Completion:
Once all customers have been processed, the dialog is closed, and a message box appears to inform the user that the processing is complete.
Enhancing the User Experience
Using a progress indicator, as demonstrated above, provides several key benefits:
Feedback to Users:
Users can see that the system is actively processing data, preventing confusion about whether the system is frozen or unresponsive.
Transparency:
Showing the user how many records are processed and how many are left gives them a sense of control and transparency. This is particularly important in operations that may take some time to complete.
Improved Efficiency:
A progress indicator can help manage user expectations. They know when to expect the task to finish, which can help reduce anxiety, especially when dealing with large datasets.
Simulated Delays:
The Sleep function, although unnecessary for production code, allows you to simulate delays and test how the progress indicator behaves during slow operations. In real scenarios, these delays could be replaced by actual business logic like API calls or heavy data processing.
Further Customizations
While this example uses a basic dialog to show the progress, you can customize the behavior and appearance further:
Progress Bar: Instead of a simple message, you could implement a more visual progress bar that updates dynamically as records are processed.
Custom Messages: You could also tailor the messages to provide more specific details about the task at hand (e.g., "Updating customer contact information").
Error Handling: Add proper error handling to ensure that if any issues arise during the processing, the dialog can handle it gracefully (e.g., by showing an error message).
Output
Conclusion
Integrating a progress indicator is a simple yet effective way to improve user experience in Business Central. By using a dialog box to show the status of long-running tasks, you ensure users are always informed and never left wondering if the system is working. Whether you are processing customers, updating records, or handling large data sets, the approach outlined above can be applied to a wide range of scenarios.
By providing feedback and managing user expectations, you enhance the usability and professionalism of your Business Central application.