Skip to content
Isolated Storage in Business Central report extensions

Using Isolated Storage on Report Extensions

Daniel Gorski
Daniel Gorski June 15, 2022
2 min read

Do you want to learn more about Isolated Storages?

Isolated Storage is a data storage that provides isolation between extensions, so that you can keep keys/values in one extension from being accessed from other extensions.

Read the full documentation here: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-isolated-storage

Lets extend the standard "Copy Purchase Document" report to get some customization there.

reportextension 50300 "BIT Copy Purchase Document" extends "Copy Purchase Document"
{
    requestpage
    {
        layout
        {
            addlast(Options)
            {
                field(CopyHTMLTexts; CopyHTMLTexts)
                {
                    ApplicationArea = All;
                    trigger OnValidate()
                    begin
                        if IsolatedStorage.Contains('Html') then
                            IsolatedStorage.Delete('Html');
                        IsolatedStorage.Set('Html', Format(CopyHTMLTexts));
                    end;
                }
            }
        }
    }

    var
        CopyHTMLTexts: Boolean;

}

After we published the code of our first implementation we discovered a very strange behaviour in our local docker container and even in our SaaS tenant.

By validating that field on my requestpage the webclient throws an exception:

Screen recording of toggling the CopyHTMLTexts field in the Copy Purchase Document dialog, which crashes the web client to a full-page 'Something went wrong' error screen

Ok, something went wrong, but what exactly?

Let take a look at the event log by running powershell and the "Get-BcContainerEventLog"

command:

Get-BcContainerEventLog output with the InvalidCastException detail highlighted, showing 'Unable to cast object of type NCLReportExtension to type NCLPageExtension'

Ok that's the problem:

Unable to cast object of type 'Microsoft.Dynamics.Nav.Runtime.NCLReportExtension' to type 'Microsoft.Dynamics.Nav.Runtime.NCLPageExtension'.

If you get this kind of an error just move your code into a procedure to cast it correctly ;-)

reportextension 50300 "BIT Copy Purchase Document" extends "Copy Purchase Document"
{
    requestpage
    {
        layout
        {
            addlast(Options)
            {
                field(CopyHTMLTexts; CopyHTMLTexts)
                {
                    ApplicationArea = All;
                    trigger OnValidate()
                    begin
                        SetIsolatedStorage();
                    end;
                }
            }
        }
    }

    local procedure SetIsolatedStorage()
    begin
        if IsolatedStorage.Contains('Html') then
            IsolatedStorage.Delete('Html');
        IsolatedStorage.Set('Html', Format(CopyHTMLTexts));
    end;

    var
        CopyHTMLTexts: Boolean;

}

Screen recording of toggling the renamed BITCopyHTMLTexts field after the fix, now working without the web client crashing

Yes!

Related posts

▸ All posts
Default Line Type behavior in Business Central

Document Default Line Type in Business Central

May 07, 2024 · Daniel Gorski

The 'Document Default Line Type' in Business Central only applies to the first line. A small AL event subscriber keeps it for every new line.

Read More
Read More: The Line Type Myth: Default Line Types in Business Central
AL runtime versions in Business Central

Business Central Runtime Versions List

February 06, 2024 · Daniel Gorski

Which AL runtime version belongs to which Business Central release, from runtime 1.0 (BC 12) to 16.0 (BC 27), and how to pick the runtime in app.json.

Read More
Read More: Navigating the Runtime Landscape in Business Central
Using OpenAI to write AL code for Business Central

Writing Business Central AL Code with ChatGPT

December 03, 2022 · Daniel Gorski

How OpenAI's ChatGPT helps Business Central developers write AL code – from a table design to a full page, and what you still need to adjust.

Read More
Read More: Writing code with a text-based AI for Business Central