Upon opening the form, the ‘Engine SN’ field must be disabled.
When we select a Document Number, the line items of that Quote or Order get populated. If even one of these items’ class code is ‘S/N’, we enable the ‘Engine S/N’ field and map UDF5 to it if it holds a value.
The ‘Engine S/N’ field can also be enabled or disabled when items are added or deleted from the list of line items.
If ‘Engine SN’ is enabled, we keep the Print option disabled unless Engine SN is populated.
Lastly, update UDF5 if ‘Engine SN’ was populated on the Sales Transaction form.
To achieve step 1, we create a trigger with the trigger type and event being set to ‘Focus Event – Form Pre’. This means that the actions described in the script will run just before the form opens. We can use the following helper function to enable (true) or disable (false) fields and buttons on the form.
To understand step 2 and 3, we need to understand how to run SQL code in GP. We’re using SQL to check how many line items’ class code is ‘S/N’ or not.
We start by defining a parameter list; this is essentially where we define variables that stores information retrieved in our trigger script from the form, which is then used in our SQL statement. In our list, we define three variables: ‘Class Code’, ’SOP Number’, and ‘SOP Type’.
We then write a simple SELECT-FROM-WHERE statement to retrieve this information as shown below:
‘’/*%(number)%*/ corresponds to their respective variables ‘Class Code’ (1), ‘SOP Number’ (2) or ‘SOP Type’ (3)
Now that we know what parameter lists are and how we use them in SQL scripts, let us go over how to use them in our trigger scripts. For step 2, like the triggers demonstrated in the previous post, we use the ‘Focus Event – Form Changed’ trigger to run whenever Document (SOP) Number changes. We start our trigger script by running our SQL script to check if any of the line items have class code as ‘S/N’. To run SQL in our trigger set up, we use helper functions go through 3 steps:
Load the Parameter List:
Set the Parameter List:
(We change the ‘Position’ according to the variable we’re setting)
Lastly, Run the SQL Script:
Now that we have run the SQL script, we replace ‘warning MBS_Text_Field’ with the required logic; More specifically, we use previously described methods to make the script enable ‘Engine SN’, disable ‘Window Print’ and populate ‘Engine SN’ with UDF5.
For step 3, we create two separate triggers ‘Focus Event – Scroll Change’ and ‘Focus Event – Scroll Delete’ for when we Add or Delete a line item respectively. We then enable or disable ‘EngineSN’ by running the SQL script as explained earlier. We get through step 4 by creating a simple ‘Focus Event – Field Changed’ trigger for the ‘Engine SN’ field and then enable or disable print based on an ‘ifempty’ clause for the ‘Engine SN’ field. Finally, step 5 can be achieved through a simple ‘Set Table’ helper function.
When approaching a project with so many triggers such as this one, try to describe all possible use-cases and build a skeletal idea of how you would like to build your solution since all these triggers may endlessly fire each other and crash.