Skip to main content

Improved performance features of Business Central 17

 In the training I’ve done to some partners last week, when talking about performances I shared an example of an extension with 3 features that I think are not so well known but that have a significant impact on how your code performs, expecially on a SaaS environment. That extension used the following features:

  • Partial record loading
  • Temporary Tables
  • QueryCategory

The Partial record capability is a new feature available starting from Dynamics 365 Business Central 2020 Wave 2 (v17) and I think it’s one of my top personal desiderata from years.

This feature permits you to load only the needed fields of a recordset (when accessing a data source) instead of loading the entire set of fields. This is particularly useful on reports and OData pages because you can avoid to do a SELECT * (plus JOINS with all the extension’s tables) and instead doing a SELECT of only the fields you need.

Now you can do something like:

procedure TestPartialRecord(): Decimal
    var
        Item: Record Item;
        total: Decimal;
    begin
        Item.SetLoadFields(Item."Unit Cost");
        if item.FindSet() then
            repeat
                total += item."Unit Cost";
            until Item.Next() = 0;
        exit(total);
    end;

As you can see in the above sample, you can use SetLoadFields to set which fields you want to retrieve in your operation ad the next FindSet() will retrieve only those fields (without loading extra fields and loading fields that comes from tableextensions of the Item table).

If you try to access a field that was not set to be loaded, in this case the platform performs an implicit GET operation on the record and loads that missing field.

You should not use partial record loading if you’re doing operations like inserts, deletes or if you’re using temporary records because in this case it’s required that the record is fully loaded.

The second feature explained on that example was the usage of Temporary tables. The concept of temporary tables is the same as in the past: they’re a temporary variable that holds data, but its data is not stored in the database but held in memory until you close or deallocate the table (A temporary table reduces the load on both the network and the SQL database backend).

For creating a temporary table, you’ve essentially the following ways:

  • using a temporary record variable (like TempItem: Record “Item” temporary;)
  • setting the SourceTableTemporary property on a page to true
  • Setting the TableType property of a table to Temporary (finally!)

With Dynamics 365 Business Central v17 you can declare a table as temporary like in the following example:

table 50100 MyTable
{
DataClassification = CustomerContent;
TableType = Temporary;
fields
{
...
}
}

The advantage of this way of declaration is that the table schema isn’t synchronized with the database and so it does not have restrictions on breaking schema changes.

The third feature present on that sample was the usage of the QueryCategory property. I think that this is quite hidden, but with this property you can now execute a query object from a page by defining a query in AL and then specifying that property by setting a comma-separated list of query categories that this object can support.

As an example, this is a query defined in AL:

query 50100 "Top 10 Customer for Sales SD"
{
    Caption = 'Top 10 Customer Sales SD';
    OrderBy = Descending(Sum_Sales_LCY);
    TopNumberOfRows = 10;
    QueryCategory = 'Item List', 'Customer List';

    elements     {         dataitem(Cust_Ledger_Entry; "Cust. Ledger Entry")         {             filter(Posting_Date; "Posting Date")             {             }             column(Customer_No; "Customer No.")             {             }             column(Sum_Sales_LCY; "Sales (LCY)")             {                 Method = Sum;             }         }     }
}

The result of this is that you can immediatly execute the query from the specified pages (like a SmartList):

These are small tips, but that can affect a lot the performances of your code. Please keep them in mind and start using them when needed. Loving this work on the performance side… 🙂

Comments

Popular posts from this blog

AL Development 03 - How to Develop New Report in AL?

Hi Readers, Now its time to develop the most important part of Navision which client desire the most yes you are correct i am talking about Reports. As we know to develop any solution in Business Central we must start working on AL Code Extension so from this blog you will get to know the detailed step how to create a Report through AL Code in business Central. Note: As of now there is no provision to customise the base report. Let’s try to create a simple report. Add new file with .al extension in your project folder through visual studio code My File Name is My_report.al  Code Snippet for adding a new Report, use snippet treport as shown below: Next Step to set these Report Properties - • Assign ID and Provide a name of the Report that you are adding. • Set UsageCategory to ReportsAndAnalysis. • Set ApplicationArea to All. As you select the treport snippet then a default structure of the report is created as below: Basically, there are 3...

Custom sheet name in RDLC Reports

Hi Readers, In this article we are going to discuss how to change the excel sheet name while using base Navision SAVEASEXCEL functionality. Applicable for RDLC reports of Navision and SSRS reports. Let’s say we have the following report that shows total sales by product category by territory:   When we export this report to Excel, we’d like each territory to appear in its own worksheet and each worksheet named after its territory: How do we make this work? Easy! 1) Put every group on its own page. 2) name each page using the same field the group uses. Step 1: Put each group on its own page To put each group on its own page, open the group’s property window. Then, in the Page Breaks category, put a check mark in the Between each instance of a group check box. Click OK to complete this step. Step 2: Name the pages of the group With the group selected in the Row Group s panel, press F4 to open the Properties window. Next, expand the Group ...

AL Development 01 - How to Develop New Table in Database?

Hello readers, As we know to develop any solution in Business Central we must start working on AL Code Extension so from this blog you will get to know the detailed step how to create a table through AL Code in business Central. Requirement : Need to create a new table with below fields: Now let’s Start: Try to keep a naming standard for your projects; As I am using the combination of Table description +Table-ID, you can use your own naming convention. So, my table file name is: My_Table50129.al AL provides a list of the snippets to make it easy for developers to add objects in extension. Snippet for getting a table layout use snippet ttable (here we have to t as prefix for every type of object we want to create in AL) as shown below: Now Assign the ID and name of the table as below: As you select the ttable from the list a default table design structure is created as shown below: You can divide the whole table into 4 Sections - · F...