#GPPT Purchase Order Processing Lock Cost Part 2

David Meego - Click for blog homepageThis article continues the creation of a GP Power Tools customization to prevent POP Receivings from updating the Originating Invoice Cost field on the Item Vendors Maintenance window.

Please make sure you have read the previous article before continuing:

In the previous article we used GP Power Tools to identify the table and field we want to work with as well as the script responsible for making the change to the field during the receivings posting process.

This article shows how we can use this information to stop the value getting updated when receivings transactions are posted.

Restoring the previous value

The next step is to adjust the existing POP LOCK COST trigger so that it restores the previous value back to the table.

  • Open the Project Setup window (GP Power Tools >> Cards >> Project Setup). Pull up the POP LOCK COST project if it is not the Current project.
  • Double click on the POP LOCK COST Trigger to open the Trigger Setup window.
  • On the Script Tab, remove the code from the TRIGGER_ON_DB_ADD case and update the TRIGGER_ON_DB_UPDATE case as follows:
case IN_Operation
	in [TRIGGER_ON_DB_ADD]

	in [TRIGGER_ON_DB_UPDATE]
		if IN_NewValue <> IN_OldValue then
			change table IV_Item_MSTR_VNDR;
			column("'Last Originating Cost'") of table IV_Item_MSTR_VNDR = IN_OldValue;
			save table IV_Item_MSTR_VNDR;
			if err() <> OKAY then
				OUT_Condition = true;
			end if;
		end if;

	else
end case;

Note: This code issues a change table command to enable writing to the table record passed into the trigger handler, restores the Last Originating Cost field to the IN_OldValue which was captured when the table record was last read, and then uses the save table command to write the record. The error check sets OUT_Condition to true if there is an issue, we can then use the options on the Action Tab to display a dialog or system alert (if desired).

  • On the Options Tab, ensure that the Allow Trigger Recursion (Not Recommended) option is NOT selected. This will ensure that the save command in the trigger does not cause the trigger to fire again and Microsoft Dynamics GP to enter an infinite loop and hang. By default, this option is never selected and it is just a precaution to make sure.

  • Click Save and close the window.
  • Back on the Project Setup window, click Start >> Start Project Triggers.
  • Click on the Open Form hyperlink to open the Item Vendors Maintenance window.
  • Select an Item and Vendor, change the Originating Invoice Cost field and click Save.
  • Pull up the same Item and Vendor and the previous value should be restored.

We now have the restoring of the previous value working, but it is working all the time and preventing any change to this field via the Microsoft Dynamics GP user interface. The next step is to control when the restoring trigger works so that it only restores when posting receivings transactions.

Controlling when to restore the previous value

The next section uses a method that I call the “Three Trigger Technique“. The idea is that we can use two additional triggers to control when our original triggers works. From our previous research we know that the form level function PostItemVendor() of form IV_TrxWorkLine is the code that updates the ‘Last Originating Cost’ on the IV_Item_MSTR_VNDR table. We are going to use a memory parameter to flag when the script is active and then adjust our original trigger to only work when that flag is true.

Note: We know that the script is a form level function as it has parenthesis “()” and “of form” in its name.

  • From the Project Setup window click Add >> Trigger Setup to open the Trigger Setup window. If asked to stop triggers, click Yes.
  • Enter Trigger ID: POP LOCK COST A, Trigger Description: Enable POP Lock Cost Trigger on table save, and select the Do Not Activate Logging Mode and Minimize Log Entries checkboxes
  • Set Trigger Type: Function, Trigger Event: Form Level, Trigger Attach: Before Original.
  • On the Resource Tab, select Product Name: 0: Microsoft Dynamics GP, Form Name: IV_TrxWorkLine and Function Name: PostItemVendor.

  • On the Script Tab, place the cursor at the beginning of the line “OUT_Condition = true;”.

  • Press Enter to make a blank line and up arrow to move back to the line.
  • Click on the Helper button to open the Helper Functions window.
  • Select Select Helper Function >> Working with Parameters (Memory Based) >> Set a memory parameter value and set the Datatype to Boolean.

  • Click OK to insert Help Function.
  • While the inserted lines are still highlighted, press tab once to indent them.
  • Edit the script to change <Variable> to true and “Variable” to “POP Lock Cost”.

  • Click Duplicate >> Duplicate Trigger. Enter the new Trigger ID as POP LOCK COST B and click OK. Duplicating saves the source Trigger automatically.

  • Change the Trigger Description to say Disable instead of Enable.
  • Change the Trigger Attach to After Original.
  • On the Script Tab, change the MBS_Memory_Boolean value to false;

  • Click Save and close the window.
  • Back on the Project Setup window, double click on the POP LOCK COST Trigger to open the Trigger Setup window.
  • On the Script Tab, click at the beginning of the “change table IV_Item_MSTR_VNDR;” line.
  • Press Enter to make a blank line and up arrow to move back to the line.

  • Click on the Helper button to open the Helper Functions window.
  • Select Select Helper Function >> Working with Parameters (Memory Based) >> Get a memory parameter value and set the Datatype to Boolean.

  • Click OK to insert Help Function.
  • While the inserted line are still highlighted, press tab three times to indent it.
  • Edit the script to “Variable” to “POP Lock Cost”.

  • On the line below the Helper Function call, add “if MBS_Memory_Boolean then”.
  • Add the matching “end if;” in between the existing two “end if;” lines and indent the code between the if and end if lines.

  • Click Save and close the window.

Testing the customization

  • Back on the Project Setup window, select Start >> Start Project Triggers.
  • Test saving on the Item Vendors Maintenance window. This should now save correctly.
  • Now test posting a receivings transaction and the value should remain unchanged.

Deploying the customization

As long as GP Power Tools is correctly installed on all workstations and servers where GP is installed, deployment is just a matter of setting the triggers to start automatically.

  • On the Project Setup window, to ensure log entries are only created if there are errors, select Update Triggers >> Mark All as Minimize Logs.
  • To deploy to all users, select Update Triggers >> Mark All as Automatic Start. The code will take effect next time a user logs in or switches company.

Backing up the customization

  • On the Project Setup window click the Export button to export the project and its components.

Moving between test and live systems

If you have developed this code on a test or development system and want to move it to a live system, follow these steps:

  • Copy the backup *.dbg.xml file created in the previous step to the live system.
  • If this is the first time importing the project use the Configuration Export/Import window (GP Power Tools >> Routines >> Configuration Export/Import). Select the file and click Import. Then click OK on the confirmation window.
  • If the project already exists on the live system, use the Project Setup window instead. Select the file and click Import. Then click OK on the confirmation window.
  • The code will be active on next login or after switching companies, or you can use start them manually from the Project Setup window.

This simple example, using three triggers can avoid costly errors in your purchase orders.

Download the example code, import using the Configuration Export/Import window:

Please come back next week for an optional enhancement to this customization:

For more information see:

David

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

One thought on “#GPPT Purchase Order Processing Lock Cost Part 2

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.