
This is the third article in the series on making window fields required. If you have not yet read the introduction article to the series, please read that first:
This example uses GP Power Tools code to make the Tax Registration Number field on the Vendor Maintenance Options sub window (same form) required.
As the Vendor Maintenance (PM_Vendor_Maintenance) form uses the required() function against the form’s main window only, making the field required with code or Modifier will not work to prevent saving.
So, we will add a check and display a specific warning and then open the sub window and place the focus on the required field.
To make this example work we need the following to happen:
- Change the field’s Object Property: Required to true so its prompt is highlighted.
- Just before Saving, check if the field has a value, and display a warning message if it hasn’t.
- Prevent the Save to table from occurring if the field is empty.
- Open the sub window and place the focus on the required field.
The following VENDOR_TAX_NUMBER project achieves these points with 4 triggers and a script.
Trigger VENDOR_TAX_NUMBER_01
This trigger runs before the Save event. For this window, saving to the table happens in the Save() form level function. You can capture logs and look at the Script Log to identify if the save happens from a field change script or from a form level procedure or function.
The trigger script will check if all the required fields on the main window have already been entered. It is not worth us checking for our particular field if the other required fields have not yet been entered. Then we check if our ‘Tax Registration Number’ field is empty and, if it is, we load and execute delayed the VENDOR_TAX_NUMBER_01 script to open the window and set the focus.
The final step is to prevent the original Save event from executing. The reject script command can only be used with field change scripts and so cannot be used with a function. The only method possible for this case was to force a required field error, by temporarily clearing the Vendor Name to cause it to fail. Storing the Vendor Name in a Memory Parameter allows us to restore the Vendor Name in the next trigger.
As allowing the Required Field error will open a dialog, this code will also enable the temporarily disabled trigger VENDOR_TAX_NUMBER_04 to close the standard dialog before the VENDOR_TAX_NUMBER_02 triggers displays our custom dialog.
Trigger VENDOR_TAX_NUMBER_02
This trigger runs after the Save event. It restores the Vendor Name, if required, and deletes the Memory Parameter used. You might see the Vendor Name flicker when saving as it is cleared and restored.
Then it checks if the required field has been entered. If needed, we set OUT_Condition = true and use the Actions tab to display the following message as a simple system dialog.
Trigger VENDOR_TAX_NUMBER_03
This trigger runs before the Window Pre event of the main window of the PM_Vendor_Maintenance form. The Window Pre event on a form’s main window is triggered when the window is opened and each time the form is restarted (eg. after save, clear or delete). The code is simply a call to the Field_SetBooleanProperty() function to change the field’s Required property to true. No additional actions are needed.
Trigger VENDOR_TAX_NUMBER_04
This trigger runs after the Warning_Dialog event and is used to automatically close the standard warning dialog opened because we forced the original code’s required check to fail by temporarily clearing the Vendor Name. It checks for the correct Warning_Dialog message number (2351) and then “clicks” the OK Button on the SY_Error_Message form to close the window. You might see the standard window flash up before it is closed.
This trigger is configured on the Options tab to start as temporarily disabled and to disable itself after execution. It is enabled when needed by the VENDOR_TAX_NUMBER_01 trigger.
Runtime Execute Script VENDOR_TAX_NUMBER_01
This script will open the Vendor Maintenance Options (PM_Vendor_Maintenance_Additional_Information) window if it is not already open and then set the focus to the ‘Tax Registration Number’ field. It is executed by the VENDOR_TAX_NUMBER_01 trigger to run delayed, so that it happens after the dialog is closed.
Downloading and Installing
Download the example code, import using the Project Setup window (without any project showing, select the path to the xml file and click Import):
The code will be active on next login or after switching companies, or you can start the triggers manually from the Project Setup window.
More Information
For more information see:
- #GPPT Making Window Fields Required and Why It Does Not Always Work
This article contains the links to the other sample projects in the series.
- GP Power Tools Portal: http://winthropdc.com/GPPT
- GP Power Tools Samples: http://winthropdc.com/GPPT/Samples
- GP Power Tools Videos: http://winthropdc.com/GPPT/Videos
Hope you find this example useful.
David
This article was originally posted on http://www.winthropdc.com/blog.


