Edit

Share via


Error handling in prompt dialogs

CHANGED IN: Business Central 2024 release wave 2

Error handling is a critical aspect of creating seamless user experiences in applications. In Business Central 2024 release wave 2, enhancements to Copilot prompt dialogs allow errors and messages to be displayed directly within the dialog, eliminating the need for separate popup dialogs. This documentation explains how to use supported error patterns, such as Dialog.Error(), Dialog.Message(), and ErrorInfo, to manage errors effectively in prompt dialogs. You'll also find examples demonstrating how these patterns work, along with best practices for rendering messages and errors inline.

If the code throws more than one message, only the last message is shown, but the user is informed about the total number of issues. If an error is thrown, any subsequent message is suppressed. If the error or message contains line breaks, these line breaks are ignored, as opposed to when they're rendered in dialogs.

Example 1: Rendering multiple messages thrown by Message() in the prompt dialog

The following code snippet illustrates throwing multiple messages, using Message(), when the user chooses the Generate button in a prompt dialog.

page 50110 PromptDialog
{
    PageType = PromptDialog;

    layout
    { ... }

    actions
    {
        area(SystemActions)
        {
            systemaction(Generate)
            {
                trigger OnAction()
                begin
                    Message('First message, which isn''t shown in the prompt dialog');
                    Message('Last message, which is shown in the prompt dialog');
                end;
            }
        }
    }
}

When you select the Generate action in the Copilot prompt dialog, the last message appears inline in the Copilot prompt dialog, along with an indication that there were more messages.

Example of rendering a message in the prompt dialog

Example 2: Rendering an error thrown by Error() in the prompt dialog

In this example, an Error() is thrown when the user chooses the Generate button in a prompt dialog.


page 50110 PromptDialog
{
    PageType = PromptDialog;

    layout
    { ... }

    actions
    {
        area(SystemActions)
        {
            systemaction(Generate)
            {
                trigger OnAction()
                begin
                    Error('This is an example of rendering an error that happens in the prompt dialog, e.g. during Generate');
                end;
            }
        }
    }
}

Here, the error appears inline.

Example of rendering error thrown in prompt dialog

Example 3: Rendering an error thrown by ErrorInfo in the prompt dialog

The last example illustrates using the ErrorInfo type when the user chooses the Generate button in a prompt dialog.

page 50110 PromptDialog
{
    PageType = PromptDialog;

    layout
    { ... }

    actions
    {
        area(SystemActions)
        {
            systemaction(Generate)
            {
                trigger OnAction()
                var
                    ErrorInfo: ErrorInfo;
                begin
                    ErrorInfo.Title('Error info title');
                    ErrorInfo.Message('Error message');
                    ErrorInfo.DetailedMessage('Detailed error');

                    Error(ErrorInfo);
                end;
            }
        }
    }
}

Here, the ErrorInfo message appears inline, and the title is used as a tooltip. The detailed message is ignored.

Example of rendering an errorinfo message in the prompt dialog

The PromptDialog page type
Prompting using a floating action bar
Prompting using a prompt guide
User experience guidelines for errors