
This is the second 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 Customer Maintenance Options sub window (same form) required.
As the Customer Maintenance (RM_Customer_Maintenance) form uses the required() function against the form and not just the main window, making the field required with code or Modifier will work and prevent saving. However, the dialog will not remind you to look on the Options sub window to find the required field.
So, we will add our own 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 CUST_TAX_NUMBER project achieves these points with 2 triggers and a script.
Trigger CUST_TAX_NUMBER_01
This trigger runs before the Save event. For this window, saving to the table happens in the ‘Save Record’ field’s change script. 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 CUST_TAX_NUMBER_01 script to open the window and set the focus.
Then we set OUT_Condition = true and use the Actions tab to display the following message as a simple system dialog.
The final step is to prevent the original Save event from executing, which we can do by using the Issue Reject Script option on the Actions tab. This works as the Save event code is contained in the ‘Save Record’ field’s change script and so can be stopped with a reject script command.
Trigger CUST_TAX_NUMBER_02
This trigger runs before the Window Pre event of the main window of the RM_Customer_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.
Runtime Execute Script CUST_TAX_NUMBER_01
This script will open the Customer Maintenance Options (RM_Customer_Options) window if it is not already open and then set the focus to the ‘Tax Registration Number’ field. It is executed by the CUST_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.


