#GPPT Making Tax Registration Number on Purchasing Vendor Detail Entry Required

David Meego - Click for blog homepageThis is the sixth 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 Purchase Order Entry – Purchasing Vendor Detail Entry sub window (separate form) required.

As the Purchase Order Entry (POP_PO_Entry) form uses the required() function against the form’s main window only and the required field is on a completely separate form anyway, 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 POP_TAX_NUMBER project achieves these points with 3 triggers and a script.

Trigger POP_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.

Note: Even though the editing of the ‘Tax Registration Number’ field is on a separate form, the field is copied to the POP_PO_Entry form’s table buffer of POP_PO table. Using the GP Power Tools Helper functions we can get the value of a field from a table buffer on a form, so we can read the value.

Then we check if our ‘Tax Registration Number’ field is empty and, if it is, we load and execute delayed the POP_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. The reject script command can only be used with field change scripts and so cannot be used with a function. In this case it was possible to stop the Save() function because it calls the form level function AreChildWindowsClosed() to check if any windows are open. Using another trigger POP_TAX_NUMBER_02 we can make the save fail by faking that a child window is open.

Trigger POP_TAX_NUMBER_02

This trigger runs after the AreChildWindowsClosed() form level function and uses the “Form Level with Parameters” option to get access to the Arguments of the function. It sets the first argument, the returned boolean value to false, thus making the calling Save() form level function think a child window is open and it aborts the save. Logging the scripts identified that the Save() function called AreChildWindowsClosed() function and changing the result returned might be an option to force the save to abort.

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 POP_TAX_NUMBER_01 trigger.

Trigger POP_TAX_NUMBER_03

This trigger runs before the Window Pre event of the main window of the SOP_Customer_Detail_Entry 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.

Note: The Purchasing Vendor Detail Entry window does not check required fields when OK is clicked. so the only check is the code added by this project.

Runtime Execute Script POP_TAX_NUMBER_01

This script will open the Purchasing Vendor Detail Entry (POP_PO_Vendor_Detail_Entry) window if it is not already open and then set the focus to the ‘Tax Registration Number’ field. It is executed by the POP_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:

Hope you find this example useful.

David

This article was originally posted on http://www.winthropdc.com/blog.

Leave a Reply