#GPPT How to improve Dynamics GP with a little bit of GP Power Tools – Part 3

David Meego - Click for blog homepageContinuing with this week’s series on customising the Payables Transaction Entry window using GP Power Tools, today we create the Trigger and test it is working.

If you missed the previous articles please check them out below:

The next step now that we have our Project, SQL Script and Parameter List created is to create the Trigger script to pull everything together.

Create the Trigger

Creating a trigger in GP Power Tools has five parts to it, which correspond to the window’s header section and the four tabs in the window’s body section. We will work our way through each part so you can see what it does for you.

  1. From the GP Power Tools Area Page, select Cards >> Trigger Setup.
  2. Enter a Trigger ID: VENDOR REMIT AD
  3. Enter a Trigger Description: Vendor Remit to Address check
  4. Check the option: Start Trigger Automatically on Login
  5. Check the option: Do not activate Logging Mode
  6. Check the option: Minimize Log Entries (Errors only)

The last three options make the trigger start automatically without enabling any of the logging capabilities of GP Power Tools and ensure that if the code is working properly, it does not add extra entries into the user’s GP Power Tools log file.

Registering the Trigger

In this section, we select the type of trigger we need and the resource against which it should be registered. We want a trigger which runs after the change script of the Vendor ID field on the Payables Transaction Entry window. We will use a lookup to select the resource, but you can just type in the Dexterity Technical Names if you know them.

  1. Select Trigger Type: Focus Event
  2. Select Trigger Event: Field Change
  3. Select Trigger Attach: After Original
  4. You can use the Menu Lookup or the Dictionary Lookup against Form Name to select the resource. As the window is directly accessible from the menus it is faster to use the Menu Lookup.
  5. Double click Transactions, double click Purchasing.
  6. Locate Payables Transaction Entry and double click to open the form.
  7. Double click on the Main: Payables Transaction Entry window.
  8. Click in the list of fields and start typing Vendor ID.
  9. Double click on Vendor ID to select the field.

 

Defining Trigger Actions

There are a number of default actions which can be initiated from a trigger. Most of these are related to the debugging features of GP Power Tools, but can also be used with non-logging triggers. Actions can be triggered when a condition is met, when a condition is not met or always regardless of condition. The condition is based on a Boolean variable passed out of the script associated with this trigger. Actions can include displaying system dialogs or desktop alerts, sending emails, capturing screenshots and exporting table data.

For non-logging Triggers, you can also reject records on a scrolling window fill script, reject script to prevent original code from running (Before Original Focus triggers only), keep the focus on a field and even restore the previous value to a field.

  1. Click on the Actions Tab
  2. Check the option: Display Message to screen using desktop alert. This is temporary for testing and will be changed later.
  3. Leave remaining Actions settings as default, no further changes needed

Defining Trigger Options

The trigger can have a number of options specified. Other than assigning to a Project or linking to a Parameter List, you can specify dates for the trigger to be active (or not active). When using scheduled events, there are some addition options. When capturing logs, you can specify which logs you desire. You can also make a trigger automatically stop or disable itself if you only want it to run once per session or once in total.

  1. Click on the Options Tab
  2. Enter or select via lookup the Project ID: VENDOR REMIT AD
  3. Leave the Parameter ID blank. We are going to use the Parameter ID, but we will use it programmatically instead of having the Parameter List window opening.
  4. Leave remaining Options settings as default, no further changes needed

Note: You can use the Users Button for an Automatically Starting trigger to specify if you want the trigger enabled or disabled for specific users, companies or user/company combinations.

Define the Trigger Script

When the trigger event occurs, the trigger script will be executed and the value of the OUT_Condition Boolean variable passed back to control whether the trigger actions should be performed. The script is automatically populated with some default code. The code can be changed as desired. For debugging you can use the code to validate if the error condition you are looking for has occurred. For non-logging triggers you can perform any actions you can think of.

  1. Click on the Script Tab
  2. We will change the script in the next article, leave the default script for now.
  3. Click Save and close the window.

You can use the Insert button to add default programming constructs for conditional processing or loops. These can speed up development and help when you are not confident with language syntax.

You can also use the Helper button to insert helper functions to perform complex tasks for you. These can make accessing data in windows or tables in other dictionaries easy, or make calling scripts in other languages simple. We will use a number of helper functions in the next article.

Testing the Trigger

Before we finish the script, let’s make sure that the Trigger is firing correctly. To enable the trigger you have a number of options (the last option is my favourite method when developing code):

  1. Logging in again will enable the trigger as it is set to automatically start.
  2. From the GP Power Tools Logging Control window, you can select Turn on Automatic Trigger Mode >> Non Logging Automatic Start only.
  3. From the GP Power Tools Logging Control window, you can select Turn on Automatic Trigger Mode >> All Triggers for selected Project and select the project from the lookup.
  4. From the Project Setup window, select the project and click the Start Button.

Note: The last two options above require the Build 23, Last Modified: 17-Mar-2018 hotfix release or later.

To confirm the Trigger is running we can use the Trigger Status window. You can open this by clicking on the Automatic Trigger Mode hyperlink or selecting Inquiry >> Trigger Status from the GP Power Tools area page. There will be two Dexterity triggers registered for our GP Power Tools trigger.

To test the trigger, we can enter a Vendor ID on the Payables Transaction Entry window.

  1. From the Purchasing Area Page, select Transactions >> Transaction Entry
  2. On Payables Transaction Entry window, enter or select a Vendor ID.
  3. If the trigger is working, a Desktop Alert will pop up in the bottom right hand corner of the screen.
  4. You can close the transaction window and delete the incomplete transaction.

Note: Using the Desktop Alert instead of the System Dialog avoids the requirement to dismiss the System Dialog before the user can continue.

To disable the trigger, you have a number of options:

  1. From the Trigger Status window, click on the individual triggers and select Unregister >> Selected Trigger for each one.
  2. From the Trigger Status window, select Unregister >> Non Logging Triggers Only
  3. From the Trigger Status window, select Unregister >> All Triggers.
  4. From the Trigger Status window, clock on any trigger for the project and select Unregister >> All Triggers for selected Project
  5. From the Project Setup window, select the project and click the Stop Button.

Note: The last two options above require the Build 23, Last Modified: 17-Mar-2018 hotfix release or later. Also all Triggers must be unregistered before you can open the Trigger Setup window again.

Triggers are also stopped automatically when exiting Microsoft Dynamics GP or switching companies.

If you are working on a development machine and do not want triggers marked to start automatically starting when you log in. From the GP Power Tools Area Page, select Transactions >> Dex.ini Settings and Enable GP Power Tools Setup Mode:

More Information

For more information, check out the links below:

In the next article we will complete the script and test that everything works as desired.

David

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

4 thoughts on “#GPPT How to improve Dynamics GP with a little bit of GP Power Tools – Part 3

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.