Επεξεργασία

Κοινή χρήση μέσω


Error handling in prompt dialogs

CHANGED IN: Business Central 2024 release wave 2

With Business Central 2024 release wave 2, errors and messages that are thrown by the code logic in Copilot prompt dialogs surface directly inside the dialog instead of in a separate popup dialog. The Dialog.Error(), Dialog.Message(), and ErrorInfo error patterns are all supported. When you use the ErrorInfo type, both the title and description will be shown inside the dialog.

If the code throws more than one message, only the last message will be 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 are 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;
            }
        }
    }
}

As a result, when invoking the Generate action in the Copilot prompt dialog, the last message is rendered 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;
            }
        }
    }
}

In this case, the error is rendered 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;
            }
        }
    }
}

In this case, the ErrorInfo message part is rendered inline, and the title part is used for the 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