Using custom buttons on the ErrorMessageForm

The default ErrorMessageForm used by the MessageFormHelper API supports adding custom buttons so that developers can extend the functionality of the dialog. This enables the end user to receive additional information or to provide support utilities like linking to a web page or preparing an email with relevant support information.

This document describes how to add custom buttons to the error dialog. In our example we create two buttons with the functionality to copy the error message from the error dialog and to kill the session if the Debug Mode is activated in the application.

How to add new buttons to the ErrorMessageForm

In order to add custom buttons to the error dialog you need to provide a class that implements the interface Consultingwerk.Windows.Util.Forms.IErrorMessageFormButtonProvider and register it in the default service container. The table below shows the two methods which are relevant for the correct display and functionality of the buttons.



PUBLIC System.Collections.Generic.List <System.Windows.Forms.Button> GetButtonsForError (Error)

Returns the list of buttons to be added to the dialog.

The buttons should have a meaningful name.

LOGICAL HandleButtonClick (Button, Error)

Handles the click event of a custom button.


The following code snippet displays the implementation of both methods.

USING Consultingwerk.Framework.*          FROM PROPATH.
USING Consultingwerk.Framework.Enum.*     FROM PROPATH. 
USING Consultingwerk.Util.*               FROM PROPATH. 
USING Consultingwerk.Windows.Util.Forms.* FROM PROPATH.  
USING Progress.Lang.*                     FROM PROPATH.

CLASS Consultingwerk.Windows.Util.Forms.SampleErrorMessageFormButtonProvider
    IMPLEMENTS IErrorMessageFormButtonProvider:
        Purpose: Returns the List of Buttons to be added to the dialog
        Notes:   Buttons should have a meaningful name
        @param poError The error that is currently being processed
        @return The List the System.Windows.Forms.Button objects to be added 
			    to the ErrorMessageForm
    METHOD PUBLIC "System.Collections.Generic.List<System.Windows.Forms.Button>" GetButtonsForError (poError AS Error):

	    DEFINE VARIABLE oList   AS "System.Collections.Generic.List<System.Windows.Forms.Button>" NO-UNDO. 
	    DEFINE VARIABLE oButton AS System.Windows.Forms.Button                                    NO-UNDO.                                   

        oList = NEW "System.Collections.Generic.List<System.Windows.Forms.Button>" () .
		IF FrameworkSettings:DebugMode THEN DO:
			oButton = NEW System.Windows.Forms.Button () .
			oButton:Name = "Kill":U .
			oButton:Text = "Kill session"{&TRAN} . 
			oList:Add (oButton) .

        oButton = NEW System.Windows.Forms.Button () .
        oButton:Name = "Copy":U .
        oButton:Text = "Copy"{&TRAN} . 
        oList:Add (oButton) .

		RETURN oList . 


		Purpose: Handles the click event of a custom button
		@param poButton The reference to the Button that was clicked
		@param poError The reference to the error that is currently shown
		@return Logical value indicating if the Error Message Form 
				should be closed (True = Close)
	METHOD PUBLIC LOGICAL HandleButtonClick (poButton AS System.Windows.Forms.Button,
											 poError  AS Error):

		CASE poButton:Name:
			WHEN "Kill":U THEN DO:

				IF MessageFormHelper:AskQuestion ("Are you sure?"{&TRAN}) = DialogResultEnum:DialogResultYes THEN 
					System.Diagnostics.Process:GetCurrentProcess():Kill () .

            WHEN "Copy":U THEN
				CLIPBOARD:VALUE = ErrorHelper:FormattedErrorMessagesExt (poError) .

        END CASE.



In our example we use the Consultingwerk sample class. This class implements the functionality of the buttons “Kill session” and “Copy”.

Note: The „Kill Session“ button is only returned when the client session Debug Mode is activated.

The next step is to define the services. We should create a new service.xml containing the services “IErrorMessageFormButtonProvider” and “SampleErrorMessageFormButtonProvider”.

<?xml version="1.0"?>
<ttServiceLoader xmlns:xsi="">

If using services, we have to load them. So we should write the following method to load the services from the services.xml file:

    Purpose: Load the services from the services.xml
	DEFINE VARIABLE oLoader AS Consultingwerk.Framework.ServiceLoader NO-UNDO.

	oLoader = NEW Consultingwerk.Framework.ServiceLoader ().
	oLoader:LOAD ("Sample/ErrorMessage/services.xml":U). 


Now we can catch an error and visualize the error message using the ErrorHelper:ShowErrorMessage method:

The error dialog displays only the “Copy” button. If you want to show the “Kill session” button, you have to set the following code line:

    Consultingwerk.Framework.FrameworkSettings:DebugMode = TRUE.

Note: This setting is usually made in the session startup procedure or based on a setting during startup


The following screenshot displays the output with activated Debug Mode: