In the previous part of this post we discussed the theory of the Three Trigger Technique and the details of a problem that was solved using this technique.
This post will cover the actual solution used and has the scripts used so you can see the techniques in action.
Before we can look at the scripts involved we need to create two global system variables. We need to create the following Fields and then add them as Globals
‘MBS Trigger Active’ using Data Type of Boolean. This is the global system variable that tells us when we are inside the Script A mentioned previously.
‘MBS Table Reference’ using Data Type of Reference. This global system variable will be used to allow us to capture a table reference which can then be instantiated in our trigger script.
As we are running Cross Dictionary code as well, it is best practice to create a Constant for the third party dictionary.
MBS_PROD_COPIER with a value of 2992, which is the Product ID for the Copier Series.
Now we are ready to create the code. Below is the Startup script to register the triggers and the three triggers of the technique.
The Startup script registers the triggers. It checks that we are not test mode and then confirms that the Copier Series dictionary is installed before registering the triggers. There are cross dictionary triggers before and after the function Copy_PO of form QPOP_Copy. Then there is the trigger against the function SetNonIVItemID of form POP_POLine in the core Dynamics.dic.
The script below is the first trigger in the three trigger technique. It is used to set our global system variable as well as capture a reference to the table QPOP_POLine.
The next script is the second trigger of the three trigger technique. It is used to clear our global system variable and clear the previously captured table reference.
The following script is third and final script of the three trigger technique and actually contains the working code of our “fix”. The check of ‘MBS Trigger Active’ of globals is important as this prevents our trigger from running when the SetNonIVItemID of form POP_POLine function is called from anywhere else.
The rest of the code is specific to the fix and includes checks to ensure that the script we are triggering against has not returned a status code to signify it has failed, as well as checks to confirm the current document is not part of a Blanket PO. Assuming that we passed the checks the code sets the Unit of Measure using the value from the ‘U Of M’ field in the table QPOP_POLine, which was re-instantiated from the captured reference.
Don’t worry about the specifics of the actual fix here, but make sure you understand the following important concepts covered:
Three Trigger Technique
Cross Dictionary Triggers
Capturing and Using References
Please let me know if you find this information useful.
23-Nov-2009: See follow-up article Accessing a Table Buffer when it is not passed as a parameter.