Creating an action to display a message windowAdded by IBM on January 17, 2014 | Version 1 (Original)
|This action uses the viewer.messageBox function to display a message that the user must acknowledge by clicking a button. The function is also used to get a yes or no answer from the user.
This example shows how to display a message window when the user clicks a button on the form, but any event can be used. For example, a message can be displayed when the user changes the value of a field, sets the focus to another field, or types a value that is out of range.
In this example, a message window is displayed when the Close button is clicked. The message window will have "Do you wish to close the form?"
as the message, "Alert"
as its title, and two buttons: "Yes"
. The user must click one of the two buttons to proceed with the action.
To display a message when a button is clicked:
Parent topic: Action Editor
- Select the Close Button from the palette and add it to the form.
The Properties window opens.
- For this example, no changes to the Properties window are required. Click OK to close the Properties window.
- Right-click on the Close button, and click Action Editor -> Custom Action Editor.
The Action Editor window is displayed.
- From the Option dropdown menu, select type.
- Click Quick Start and click On Button Click.
The following template code is displayed in the formula text box and the word "action"
toggle(activated, 'off', 'on') == '1' ? action : ''
- With "action" highlighted, click If/Then/Else.
The If/Then/Else menu opens with the If Condition tab open.
- Click Function -> Viewer -> viewer.messageBox.
The message parameter is highlighted.
- In the formula text box, place your cursor between the quotes and type Do you want to close the form?.
- Click on caption and type Alert between the single quotes.
- Click the messageType parameter and type QUESTION between the single quotes and click OK to return to the If/Then/Else window.
In the If Condition window, an error appears because the condition does not equal either true or false.
- Click Operator -> equals (==), then String -> 1.
The error disappears and following action is displayed in the If Condition
viewer.messageBox('Do you want to close the form?', 'Alert', 'QUESTION')== '1'
- Click the Then tab. Select String -> <<Empty String .
- Type CANCEL in between the single quotation marks.
- Click the Else tab. Select String -> <<Empty String . Click OK to return to the Action Editor window.
The completed action should appear as follows:
toggle(activated, 'off', 'on') == '1'
? viewer.messageBox('Do you want to close the form?', 'Alert', 'QUESTION')=='1'
? 'CANCEL' : ''
- Click OK to apply the action and close the Action Editor.
- Click the Viewer tab to test the action. When you click the Close button, the alert message appears. Clicking the Yes button will close the form. Clicking No returns you to the form.