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

You can also use the STRMENU function to create forms that present options to the user. It is much faster to use this function than to design a form 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 done 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 need to use more than one line, then start each new line after a period rather than 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 an indicator control to show progress. For more information, see How to: Use an Indicator to Display Values. In other applications, you may want to create a window in which each field is updated while 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 type 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 clicks OK on the window.

The MESSAGE function has the following syntax.

  CopyCode imageCopy Code
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 standard application. 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.

  CopyCode imageCopy Code
MESSAGE(Text001,"No.",SalesHeader2."No.");

Text001 is a text constant that contains the following text:

Quote %1 has been changed to order %2.

NoteNote

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.

  CopyCode imageCopy Code
ERROR(String [, Value1, ...])

CONFIRM Function

The CONFIRM Function (Dialog) is used in the same way as 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.

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

The following example shows how to use the CONFIRM function.

  CopyCode imageCopy Code
IF CONFIRM('Do you want to post the journal lines and print the report(s)?',FALSE) THEN
   MESSAGE('Posting')
ELSE
   MESSAGE('No Posting');
   EXIT;

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