#GPPT Making Substitute Item 1 on Item Maintenance Options Required

David Meego - Click for blog homepageThis is the fourth 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 Substitute Item 1 field on the Item Maintenance Options sub window (same form) required.

As the Item Maintenance (IV_Item_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 ITEM_SUB_ITEM1 project achieves these points with 2 triggers and a script.

Trigger ITEM_SUB_ITEM1_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 ‘Alternate Item 1’ field is empty and, if it is, we load and execute delayed the ITEM_SUB_ITEM1_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 ITEM_SUB_ITEM1_02

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

This script will open the Item Maintenance Options (IV_Item_Additional_Info) window if it is not already open and then set the focus to the ‘Alternate Item 1’ field. It is executed by the ITEM_SUB_ITEM1_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