Views

Views in Dynamics 365 Business Central are used on list pages to define a different view of the data on a given page. Views can be defined for Pages, Page Extensions, and Page Customization. Views are defined on page extension objects to provide an alternative view of data and/or layout on an existing page, and in views on page customization objects, they can be used to provide an alternative view for a certain profile.

A view offers:

  • Filtering on multiple table fields on the source table defined for the page.
  • Sorting of the data on multiple table fields, but only in one direction; either ascending or descending.
  • Layout changes, modifying page columns, moving them, etc.

Views are defined directly in code, on the list page that they modify. The defined view or views are available to the user through Filter Pane on a page and appear in the sequence that they are defined in code.

Snippet support

Typing the shortcut tview will create the basic layout for a view when using the AL Language extension in Visual Studio Code.

Filtering and sorting

You can filter on the data in a view by using the Filters property. The following is an example of the syntax:

Filters = where ("Balance (LCY)" = filter (> 500), Name = filter ('G*'));

For more information, see Filters.

You can sort on the data in a view by using the OrderBy property. The following is an example of the syntax:

OrderBy = ascending ("Balance (LCY)", Name);

For more information, see OrderBy.

Note

All filters are applied to the table field(s), not the page field(s), which allows filtering on a table field not shown on the page.

View example

The following example shows a page customization of the Customer List page, which is available for a specific role center only; the My Role Center. Change the role center view under My Settings. The definition of the view adds a caption which is displayed on the left side in the UI. The view sorts the customer balance in ascending mode and the view modifies the layout by moving the customer balance first and adding a freeze column after it.

Important

The definition of the view section must come after any definition of layout and actions, otherwise you will get a compilation error.

profile MyProfile
{
    Description = 'My Role Center';
    RoleCenter = "Order Processor Role Center";
    Customizations = MyCustomization;
}

pagecustomization MyCustomization customizes "Customer List"
{
    layout
    {
        // Change the layout of the page
    }

    actions
    {
        // Add any actions to the page
    }

    views
    {
        addfirst
        {
            view(BalanceLCY)
            {
                Caption = 'Ordered Balance LCY';
                OrderBy = ascending ("Balance (LCY)");

                layout
                {
                    // Change the layout of the view

                    movefirst(Control1; "Balance (LCY)")

                    modify(Control1)
                    {
                        FreezeColumn = "Balance (LCY)";

                    }
                }
            }
        }
    }
}

Limitations

In general, views can in several ways be compared to page customizations. These are the limitations of views:

  • For views you can modify the same control properties as for page customization objects independently of where the view has been defined (page, page extension, or page customization level). This is validated by the compiler.
  • It is not possible to use variables or methods in a view. When writing client-side expressions for properties like Visibility, it will only be possible to use constant values or table field references. This is validated by the compiler.
  • It is not possible to create new controls for a page from a view.

See Also

AL Development Environment
Developing Extensions
Page Object
Page Extension Object
Page Customization Object
SharedLayout Property