Modifier

Partager via


Progress Windows, Message, Error, and Confirm Methods

You can use several specialized methods to display messages and gather input. We recommend that you use pages to ensure that your application has a consistent user interface. However, there are situations where you may want to use the dialog methods instead of pages. The most important uses of the dialog methods are as follows:

  • To display a window that indicates the progress of some processing that may take a long time.

  • To stop the running program to display an error message.

  • To let the user confirm a choice before the program continues running.

You can also use the StrMenu method to create pages that present options to the user. It's much faster to use this method than to design a page, which only presents a limited set of options to the user. For more information about the StrMenu method, see StrMenu Method.

Best practices for user messages

We recommend the following guidelines for writing messages for end users:

  • Write messages correctly according to the grammatical rules for your language.

  • Don't use backslashes to indicate line breaks in a message. Line formatting is completed automatically. The only exception is in the Open Method). You must use backslashes for the message to be aligned correctly.

  • Use the FieldCaption Method) and TableCaption Method) whenever possible to return names of fields and tables as strings. It's so that the user can always recognize a term that indicates a field or table name. The only exception to this is in Open Method) where you can use the field name directly. Otherwise, it can be difficult to align correctly. If you refer to a field name without using the FieldCaption method, then type the field name without any single or double quotation marks.

  • Try to write all messages on only one line. If you want to use more than one line, then start a new line after a period instead of in the middle of a sentence.

  • Don't enter the text directly in the AL code. Instead, enter it as a label so that the message can be translated.

Creating a window to indicate progress

If you have an application whose processing can take a long time to complete, then you should consider displaying a window that informs the user of the progress that is being made. It's always a good idea to inform the user that processes are still running.

A Cancel button is automatically added to every dialog window and gives user the opportunity to stop the processing.

In some applications, you may want to create a window in which each field is updated when the program is running. For example, the fields in the window, display the count of the postings made. In another application, you may want to display information about the record that is currently being processed. For example, the field in the window, displays the number of the account that is currently being processed.

To create this kind of progress window, you use the Dialog data type.

Message method

The Message Method) displays a message in a window that remains open until the user chooses the OK button.

The Message method has the following syntax.

message(String [, Value1, ...]);  

The Message method runs asynchronously, which means that the message isn't run until the method from which it was called ends or another method requests user input. The method is useful for notifying the user that some processing has been successfully completed.

For an example of the Message method, see codeunit 83 in the CRONUS International Ltd. demonstration database. The code in the OnRun trigger converts a quote into a sales order and then displays a message. The message is generated by the following code.

var
    Text001 : Label 'Quote %1 has been changed to order %2';

message(Text001,"No.",SalesHeader2."No.");  

Note

Unlike the progress window, the Message method doesn't require that you first declare a variable of the type Dialog. The Message method creates a window of its own.

Error method

The Error Method is similar to the Message method except that when the user has acknowledged the message from an Error method, AL execution ends. The Error method is also similar to the FieldError method. For more information on the FieldError method, see CalcFields, CalcSums, FieldError, FieldName, Init, TestField, and Validate Methods.

The Error method has the following syntax:

procedure MyProc()
var
    MyErrorInfo: ErrorInfo;
begin
    // setup ErrorInfo
    MyErrorInfo.Title('Error message title that the user sees.');
    MyErrorInfo.Message('Error message the user sees.');
    MyErrorInfo.DetailedMessage('(Hidden) error details for the person who needs to troubleshoot.');
    // add more properties for ErrorInfo depending on the scenario

    Error(MyErrorInfo);

    // no more AL code runs after the Error method
end;

For more information about error handling in AL, see Error handling overview.

Confirm method

The Confirm Method) is used just like the Message method to display a message. However, unlike the Message method, the Confirm method has a required return value.

The Confirm method has the following syntax.

Ok := Dialog.Confirm(String [, Default] [, Value1] ,...);  

The following example shows how to use the Confirm method.

if confirm('Do you want to post the journal lines and print report %1?', False, ReportID) then
    message('Posting')
else begin
    message('No Posting');
    exit;
end;

The false parameter in the confirm statement means that No is the default.

See Also

Error handling overview
Dialog data type