Using and Creating Views
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 11 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Mastering Views in AL: Customizing the User Experience
Introduction: Why Views Matter in Business Central
When working with Microsoft Dynamics 365 Business Central, the data landscape can be overwhelming. Users are often presented with hundreds of records in a single list page, making it difficult to find the specific information they need to perform their daily tasks. This is where "Views" become an essential component of your development toolkit. In the context of AL (Application Language) development, Views allow us to define filtered, sorted, and customized subsets of data directly within our page objects.
Understanding how to implement and manage Views is not just about aesthetics; it is about productivity and data integrity. When you create a well-designed View, you are essentially creating a shortcut for the user, allowing them to focus on the data that matters most—such as "Open Sales Orders," "Overdue Invoices," or "Items with Low Inventory." By mastering the syntax and logic behind Views, you ensure that your extensions provide a clean, professional, and highly efficient user interface that reduces navigation time and minimizes human error.
In this lesson, we will explore the mechanics of Views in AL, how to define them in list pages, the differences between platform-defined and developer-defined views, and how to craft a user-centric experience through thoughtful UI design.
Not read yet
Understanding the Anatomy of a View
In AL, a View is a way to present a filtered version of a record set. While users can create their own personal views through the Business Central client interface, developers have the responsibility of defining "System Views." These are the views that appear by default for all users, providing a baseline of utility that helps them navigate your custom tables and extensions.
A View is defined within the views section of a page object. It uses a specific syntax that combines filtering criteria and sorting orders. The primary goal is to restrict the record set to a meaningful subset, allowing the user to interact with a manageable list of data rather than an entire database table.
The Basic Structure of a View
When you declare a view in AL, you are essentially setting up a View object that contains a Filters property and a OrderBy property. Here is the standard structure you will encounter:
page 50100 "Custom Item List"
{
PageType = List;
SourceTable = Item;
views
{
view(LowStockItems)
{
Caption = 'Low Stock Items';
Filters = where(Inventory = filter(..10));
OrderBy = ascending(Description);
}
}
}
In this example, we have created a view named LowStockItems. The Filters property uses the where clause to apply a filter on the Inventory field, showing only items where the quantity is between 0 and 10. The OrderBy property ensures that the list is sorted by the Description field, making it easier for users to scan the list alphabetically.
Callout: Views vs. Filters It is important to distinguish between a view and a standard filter. A filter is a temporary state applied to a dataset, whereas a view is a saved, named configuration that persists in the UI. Views are intended to be "saved states" that users can switch between with a single click, whereas filters are often used for ad-hoc, one-time data analysis.
Not read yet
Step-by-Step: Creating Your First View
To implement a view effectively, you must understand the business requirements of the user. If you are developing an inventory management module, you should consider what the warehouse manager needs to see versus what the purchasing agent needs to see.
Step 1: Identify the Business Need
Before writing code, draft the requirement. For instance, a "Pending Shipments" view is a common requirement for sales order processing. You need to identify which fields determine the "pending" status, such as Status = Filter(Released) and Shipment Date = Filter(..Today).
Step 2: Declare the View in the Page
Open your AL file for the list page. Navigate to the views block. If the block does not exist, you can add it after the layout or actions sections.
Step 3: Define Filters and Sorting
Use the Filters property to narrow down the data. Remember to use the filter() syntax, which supports standard Business Central filter expressions like .. (range), | (or), and <> (not equal).
Step 4: Apply Captions for Localization
Always define a Caption property. If you leave it blank, the system might default to the view name, which is often not user-friendly. Use descriptive, action-oriented names.
Tip: Use Captions for Clarity Avoid naming views based on technical field names. Instead of
View_Inv_Less_10, useLow Stock Items. This makes the interface intuitive for non-technical users.
Not read yet
Advanced View Configurations
Once you are comfortable with basic filtering, you can begin to explore more complex configurations. Views in AL are not limited to simple field comparisons; they can be combined with complex expressions and even multi-field sorting.
Multi-Field Sorting
Sometimes, a single field is not enough to organize your data. You can sort by multiple fields by separating them with commas in the OrderBy property.
view(SalesByDateAndCustomer)
{
Caption = 'Sales by Date and Customer';
OrderBy = descending("Posting Date"), ascending("Sell-to Customer Name");
}
This ensures that the most recent sales appear at the top, and within those dates, the list is alphabetized by the customer name. This level of granularity is essential for reporting-style list pages.
Filtering on Related Tables
One of the most powerful features of AL views is the ability to filter based on related data. While you cannot perform complex SQL-style joins within a simple view definition, you can use flowfields or specific filter tokens to interact with related records.
Warning: Performance Considerations Be careful when filtering on fields that are not indexed. If you create a view that filters on a non-indexed field, the performance of the page load will suffer significantly as the database engine performs a full table scan. Always ensure that the fields used in your
Filtersproperty are indexed or are primary keys.
Not read yet
Onboarding and User Experience (UX)
Creating a view is only half the battle. The second half is ensuring that the user actually uses it. This is where onboarding and UI design come into play. If you build a powerful view, but the user doesn't know it exists, it provides zero value.
The Role of UI Design in Onboarding
When you introduce a new feature, you should consider how the user discovers it. In Business Central, the "Views" pane appears at the top of the list page. By default, the system shows all records. When you add custom views, they appear in the horizontal bar above the list.
- Keep it simple: Do not overwhelm the user with twenty different views. Stick to the top 3-4 most common tasks.
- Standardize Naming: Use a consistent naming convention across your extension. If you have "Open Orders" and "Released Orders," ensure they follow a similar grammatical structure.
- Use Tooltips: While views themselves don't have tooltips in the traditional sense, the surrounding UI should provide context. Use the
Captionwisely to describe exactly what the view contains.
Implementing Onboarding Tips
If your extension is complex, consider using the Teaching Tips feature in Business Central. You can trigger a teaching tip that points to the View bar, explaining to the user: "Click here to quickly filter your list for items that need reordering."
// Example of a conceptual approach to user guidance
// Note: Teaching Tips are managed via the 'User Tours' module
// Ensure your views are labeled clearly so the tour text makes sense.
Not read yet
Best Practices for Developer-Defined Views
As you develop your application, you will find that consistency is the key to a professional-looking product. Below are the industry standards for working with views in AL.
1. Avoid Over-Filtering
It is tempting to create a view for every possible scenario. However, too many views clutter the interface and make the "View Bar" difficult to navigate. Stick to the views that represent the most frequent workflows.
2. Leverage "All" as the Default
Always ensure that the default list (the view that appears when no filter is applied) represents the most comprehensive view of the data. Usually, this is simply the full list, sorted by the primary key or a creation date.
3. Localization
Always wrap your captions in a way that supports translation. Use the CaptionML property or standard translation files (.xlf) to ensure your views are accessible to users in different regions and languages.
4. Test with Large Datasets
A view that works perfectly with ten records may behave differently with ten thousand. Always test your views against a large dataset to ensure that the filters do not cause timeouts or UI lag.
Callout: The Importance of Performance When defining a view, you are essentially telling the SQL Server how to retrieve the data. A poorly constructed filter can bypass indexes, leading to slow page loads. Always analyze the execution plan if you notice a specific view is sluggish.
Not read yet
Common Pitfalls and How to Avoid Them
Pitfall 1: Hardcoding IDs
Never hardcode IDs (e.g., Status = filter(1)) in your views. Always use the field names or, if necessary, use enumeration values if the platform allows it. Hardcoding integers makes your code fragile and difficult to maintain when the underlying data structure changes.
Pitfall 2: Ignoring User Customization
Users can save their own views. If you define a system view that conflicts with a user's personal view, the system usually handles this gracefully, but it can lead to confusion. Ensure that your system views are clearly distinct from user-created ones.
Pitfall 3: Neglecting the "Clear" Functionality
Users often get stuck in a filtered view and forget how to return to the full list. Ensure that your UI design remains intuitive enough that the "Clear Filter" button is always accessible, or provide a "Reset to Default" option.
Not read yet
Comparison Table: System Views vs. User Views
| Feature | System Views (Developer) | User Views (Personal) |
|---|---|---|
| Creation | Defined in AL code | Created via the Business Central UI |
| Persistence | Persistent for all users | Persistent for the individual user |
| Modification | Requires an extension update | Can be modified at any time by the user |
| Availability | Available to everyone | Private to the creator |
| Performance | Optimized by the developer | Dependent on user filter configuration |
Practical Example: Creating a "High-Value Sales" View
Let's walk through a more complex example. Suppose you are working on a Sales Header page. You want to create a view that highlights "High Value" orders, defined as any order over $10,000 that has not yet been shipped.
pageextension 50101 "Sales Order List Ext" extends "Sales Order List"
{
views
{
view(HighValueOrders)
{
Caption = 'High Value Orders';
Filters = where("Amount Including VAT" = filter(>10000),
Status = filter(Released),
"Shipment Date" = filter(''));
OrderBy = descending("Amount Including VAT");
}
}
}
Explanation of the Code:
- Filters: We are using three distinct filters. The
Amount Including VATis filtered to be greater than 10,000. TheStatusmust beReleased(meaning the order is ready for processing). TheShipment Dateis an empty string, which in Business Central indicates that the shipment has not yet occurred. - OrderBy: We sort by the amount in descending order, so the largest orders appear at the top. This provides immediate value to a sales manager who needs to prioritize high-impact shipments.
Not read yet
Integrating Views with Onboarding
When you release a new view, you should consider how to communicate its value. In modern Business Central development, we focus on the "In-App Guidance" pattern.
- Contextual Awareness: If you are adding a view for "Overdue Invoices," consider placing a small "Cue" on the Role Center that links directly to that view.
- Tutorials: Use the
Teaching Tipsto highlight the new view the first time the user visits the page after an update. - Documentation: Include a link to a help article directly within the page, if possible, explaining the criteria used for the view.
Note: Remember that the
viewssection in AL is a declarative way to define filters. It does not replace the need for business logic in your codeunits, but it does make the UI significantly more responsive and tailored to user workflows.
Maintaining Your Views
Once your views are in production, your work isn't done. Business requirements change. What was considered a "High-Value Order" in the first quarter of the year might be different by the fourth quarter.
Periodic Review
Set a schedule to review your views. Ask the users:
- Are these views still relevant?
- Are there new criteria they need to filter by?
- Do they find the current sorting order helpful?
Version Control
Because views are defined in AL code, they are subject to version control (like Git). This is a major advantage. If you make a mistake and break a view, you can easily roll back to the previous version. Always use meaningful commit messages when changing view definitions, such as "Updated High Value Orders filter to include VAT calculation."
Not read yet
FAQ: Common Questions About Views
Q: Can I use functions in my view filters?
A: No, the Filters property in a view declaration must be a static filter expression. You cannot call AL functions or methods inside the filter definition.
Q: What happens if I rename a view in my AL code?
A: Renaming a view in code is treated as a new object by the platform. If users had saved personal variations based on the old view, they might lose those associations. Be very careful when changing names; consider using the ObsoleteState property if you need to deprecate a view.
Q: Can I hide the default "All" view? A: Generally, no. The "All" view is a fundamental part of the list page experience in Business Central. It is best practice to keep it and provide your custom views as additional options.
Q: Are views available on Mobile or Tablet clients? A: Yes, views are platform-agnostic and will render on the web client, mobile app, and tablet interface, provided the page type supports it.
Not read yet
Summary and Key Takeaways
Mastering the use and creation of Views in AL is a fundamental skill for any Business Central developer. By moving beyond a simple list of records and providing curated, filtered, and sorted views, you significantly enhance the usability of your extensions.
Key Takeaways:
- Efficiency through Curation: Views are not just filters; they are productivity tools that help users focus on the most critical data for their specific roles.
- Declarative Syntax: Use the
viewssection in yourpageobjects to define persistent filters and sorting, keeping the code clean and maintainable. - User-Centric Naming: Always use clear, descriptive captions for your views. Avoid technical jargon and focus on the business outcome (e.g., "Ready to Ship" instead of "Status_Released").
- Performance First: Always ensure that the fields used in your view filters are indexed to prevent performance degradation on large datasets.
- Consistency is Vital: Apply consistent naming conventions and design patterns across all your views to provide a predictable experience for the user.
- Evolution and Maintenance: Treat your views as living parts of your application. Review them periodically with your users and use version control to manage changes over time.
- Integration with UX: Combine your views with other UI elements like Cues and Teaching Tips to ensure users are aware of the tools you have provided for them.
By following these principles, you will create extensions that are not only functional but also a joy to use. Your users will appreciate the thoughtfulness you put into the interface, and your code will remain organized, performant, and easy to maintain as your project grows in scope and complexity. Remember, the best software is the software that feels like it was designed specifically for the person using it—and well-crafted views are a perfect way to achieve that level of personalization.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
Spend your points to unlock exam-style practice questions
Spend points to unlock MB-820 exam-style practice questions.
Practice for MB-820