Progress Windows, MESSAGE, ERROR, and CONFIRM Functions

You can use several specialized functions 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 functions instead of pages. The most important uses of the dialog functions 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 function to create pages that present options to the user. It is much faster to use this function than to design a page which only presents a limited set of options to the user. For more information about the STRMENU function, see STRMENU Function.

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.

  • When you write a message that is similar to one in the .etx file, phrase it to be as similar to the .etx message as possible. This will make messages consistent throughout the system.

  • Do not use backslashes to indicate line breaks in a message. Line formatting is completed automatically. The only exception is in the OPEN Function (Dialog). You must use backslashes for the message to be aligned correctly.

  • Use the FIELDCAPTION Function (Record) and TABLECAPTION Function (Record) whenever possible to return names of fields and tables as strings so that the user can always recognize a term that indicates a field or table name. The only exception to this is in OPEN Function (Dialog). In this function, 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 function, 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 each new line after a period instead of in the middle of a sentence.

  • Do not enter the text directly in the C/AL code. Instead, enter it as a text constant so that the message can be translated.

Creating a Window to Indicate Progress

If you have an application that performs some processing that 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 is 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 the 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 number of 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. For more information, see How to: Create a Progress Window.

MESSAGE Function

The MESSAGE Function (Dialog) displays a message in a window that remains open until the user chooses the OK button.

The MESSAGE function has the following syntax.

MESSAGE(String [, Value1, ...])  

The MESSAGE function executes asynchronously, which means that MESSAGE is not executed until the function from which it was called ends or another function requests user input. The function is useful for notifying the user that some processing has been successfully completed.

For an example of the MESSAGE function, 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.

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

Text001 is a text constant that contains the following text:

Quote %1 has been changed to order %2.

Note

Unlike the progress window, the MESSAGE function does not require that you first declare a variable of type Dialog. The MESSAGE function creates a window of its own.

ERROR Function

The ERROR Function (Dialog) is very similar to the MESSAGE function except that when the user has acknowledged the message from an ERROR function, execution ends. The ERROR function is also similar to the FIELDERROR function. For more information, see CALCFIELDS, CALCSUMS,FIELDERROR, FIELDNAME, INIT, TESTFIELD, and VALIDATE Functions.

The ERROR function has the following syntax.

ERROR(String [, Value1, ...])  

CONFIRM Function

The CONFIRM Function (Dialog) is used just like the MESSAGE function to display a message. However, unlike the MESSAGE function, the CONFIRM function has a required return value.

The CONFIRM function has the following syntax.

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

The following example shows how to use the CONFIRM function.

IF CONFIRM('Do you want to post the journal lines and print report %1?',FALSE, ReportID) THEN  
   MESSAGE('Posting')  
ELSE  
   MESSAGE('No Posting');  
   EXIT;  

The FALSE parameter in the CONFIRM statement means that No is the default.