System.GuiAllowed() Method
Version: Available or changed with runtime version 1.0.
Checks whether the AL code can show any information on the screen.
Syntax
Ok := System.GuiAllowed()
Note
This method can be invoked using property access syntax.
Note
This method can be invoked without specifying the data type name.
Return Value
Ok
Type: Boolean
Remarks
The System.GuiAllowed
method returns true if the session where your AL code is running allows you to use methods that interact with the user, such as Dialog.Open, Dialog.Update, or Dialog.Close.
If the same codeunit needs to run both in the UI but also in the background (in a scheduled task or with a job queue entry) or in a web service call (SOAP/OData/API), then use if GuiAllowed() then
calls to encapsulate AL code that interact with the user.
Example
This example shows how to use the GuiAllowed method.
if GuiAllowed then
Message('Code is running on a client.');
If the code runs on a client, which means that the user interface is available, a message box will appear with the following message.
Code is running on a client
If the code runs in a web service call or in the background, then the message will not be displayed.
Example (Shopify integration)
This example shows how the Shopify integration use GuiAllowed to provide feedback to the user when the code is running in the client, while allowing the business logic to also run in the background or being called from a web service.
procedure AddItemToShopify(Item: Record Item; ShopifyShop: Record "Shpfy Shop")
var
ProgressDialog: Dialog;
begin
if GuiAllowed then begin
ProgressDialog.Open(DialogMsg);
ProgressDialog.Update(1, SyncInformationProgressLbl);
end;
// business logic code here
if ShopifyShop."Sync Item Images" = ShopifyShop."Sync Item Images"::"To Shopify" then begin
if GuiAllowed then
ProgressDialog.Update(1, FinishSyncProgressLbl);
// business logic code here
end;
// some more business logic
end;