IsolatedStorage, a way to store global data in a session

Microsoft Definition for Isolated Storage: “Provides data isolation for extensions

 

 

Isolated Storage

“Isolated storage” is a data storage method that allows you to isolate data between different extensions, even within the same extension.

It is possible to archive key-value pairs in an isolated archive and define the scope of the archived data (through an access level called “Data Scope“).

 

Data Scope

The “DataScope” of isolated storage key pairs can be limited to:

– extension

– a specific company

– a specific user or a combination of company and user

 

Usage

In practice, it is possible to pass data between different extensions without saving data in the table or on configuration files; it can be used for example to assign global variables (AS IS for the WORKDATE) to be passed \ used within the same extension in the user \ company session.

 

Methods

The following methods are available on the IsolatedStorage data type.

 

SET

Sets the value associated with the specified key.

[Ok := ] IsolatedStorage.Set(Key: Text, Value: Text [, DataScope: DataScope])

GET

[Ok := ] IsolatedStorage.Get(Key: Text [, DataScope: DataScope], var Value: Text)

DELETE

[Ok := ] IsolatedStorage.Delete(Key: Text [, DataScope: DataScope])

CONTAINS

HasValue := IsolatedStorage.Contains(Key: Text [, DataScope: DataScope])

Example

 

DATASCOPE

 

Case example
Save “Item No.” Value in StorageKey

Save the “Item No.” In a Key to view it on other pages related to the “Item Card” page that instantiated it, then delete it when the “Item card” page is closed.

 

TESTING

On “Unit of Measure List Page” you can show the “Item No.”

 

ERRORS

Example of “Storage Key” not found (or Not Assigned)

IsolatedStorage Data Type – Business Central | Microsoft Learn

Save the "Item No." In a Key to view it on other pages related to the "Item Card" page that instantiated it, then delete it
when the "Item card" page is closed.

    // SET STORAGEKEY
    [EventSubscriber(ObjectType::Page, Page::"Item Card", 'OnBeforeOnOpenPage', '', true, true)]
    local procedure "Item Card_OnBeforeOnOpenPage"(var Item: Record "Item")

    var
        StorageKey: text;

    begin
        StorageKey := 'itemNo';
        if IsolatedStorage.Contains(StorageKey, DataScope::CompanyAndUser) then 
            IsolatedStorage.Delete(StorageKey, DataScope::CompanyAndUser);
        IsolatedStorage.Set(StorageKey, Item."No.", DataScope::CompanyAndUser);
        Message(StorageKey);       
    end;


    // DELETE STORAGEKEY
    [EventSubscriber(ObjectType::Page, Page::"Item Card", 'OnClosePageEvent', '', true, true)]
    local procedure "Item Card_OnClosePageEvent"(var Rec: Record "Item")

    var
        StorageKey: text;

    begin
        StorageKey := 'itemNo';
        if IsolatedStorage.Contains(StorageKey, DataScope::CompanyAndUser) then
            IsolatedStorage.Delete(StorageKey, DataScope::CompanyAndUser);
    end;


    // GET DATA FROM STORAGEKEY
    [EventSubscriber(ObjectType::Page, Page::"Units of Measure", 'OnOpenPageEvent', '', true, true)]
    local procedure "Units of Measure_OnOpenPageEvent"(var Rec: Record "Unit of Measure")

    var
        StorageKey: text;

    begin
        IsolatedStorage.Get('itemNo', DataScope::CompanyAndUser, StorageKey);
        message(StorageKey);
    end;