#GPPT Setting Default Sorts for Inquiry Windows

David Meego - Click for blog homepageToday, I was asked by a partner how simple it would be to default the Sort by fields on the Payables Transaction Inquiry – Vendor window to Document Date in Descending order. This is previously the type of quick tweak that you might have used VBA (Visual Basic for Application) for.

However, now that VBA is “End of Life” and is not supported on the Web Client and some windows platforms, this is a perfect customization to use the GP Power Tools – Developer Tools module for. The entire customization took me about two minutes to complete. In fact, it took much longer to write this article.

Start by opening the Resource Information window and make sure it is in Form, Window & Field mode and the “Show currently selected Window and Field information” option is selected. Then open the window you want to customize and click on the first field you want to work with.

Payables Inquiry

Come back to the Resource Information window and you will see the full details for the form, window and field, including the Technical Names you will need to write the code.

Resource Information

Open the Project Setup window and create a new project. Projects are used to combine all the parts of a project together to make it easier to develop and maintain as well as export and import. Even though this customization only needs a single trigger, it is still worth creating the project record.

Note: Enter the form name into the Open Form field, this makes it easy to test the customization as you can quickly navigate to the first window needed to test your customization.

Defaulting Project

Click the Add button and select Trigger Setup to open the Trigger Setup window. Enter a Trigger ID and Description and set the trigger to start automatically, do not activate logging and to minimize log entries.

The next step is to set the trigger type and resource to a Focus Event, on Window Pre running After Original code. Then, on the Resource Tab, you can select the resource using the Form Name and Window Name from the Resource Information window. You can also use the menu lookup or the dictionary lookup to select the window.

Note: If there is an issue with timing where the changes to the window are being overwritten by initialization code running after the window has opened, change Trigger Attach to After Original Delayed.

Defaulting Trigger 1

Click over to the Script Tab and add the 4 lines of code needed to change the value of the two drop down list fields and run the change scripts for the fields.

You can click on the second field to show its name in the Resource Information window. You can also select the fields using the Names Button.

The code lines added above the OUT_Condition = true; line are:

 'PM Sort By' of window PM_Transaction_Inquiry of form PM_Transaction_Inquiry = 5;
run script 'PM Sort By' of window PM_Transaction_Inquiry of form PM_Transaction_Inquiry;

'Sort Order' of window PM_Transaction_Inquiry of form PM_Transaction_Inquiry = 2;
run script 'Sort Order' of window PM_Transaction_Inquiry of form PM_Transaction_Inquiry; 

Note: The OUT_Condition parameter can be used to specify if the script successfully completed or if an error condition has been found. It controls whether the actions on the Actions Tab (if any are selected) are executed after the script has completed.

[Edit] If you want to change a Checkbox field, set it to true or false (lowercase). Always run script the field after making a change. Unlike VBA, you need to request the field change script to run with the run script command. This is an extra step but gives more flexibility to the coding.

To test the code, following the steps below:

  • Close the Payables Transaction Inquiry – Vendor window (if it is open).
  • From the Project Setup window, click Start >> Project Triggers.
  • Click on the Open Form hyperlink to open the window.
  • Check that the fields have defaulted as desired.

Note: The Resource Information window and Resource Finder window are part of GP Power Tools – Administrator Tools module, which is just another reason why every customer site should have the Administrator Tools.

Download the project here:

Enjoy

David

01-May-2024: Added notes about using Trigger Attach: After Original Delayed and how to set Checkbox fields. Updated to remove use of default form and default window commands.
19-Jul-2024: Updated sample download to include both PM_Transaction_Inquiry and PM_Transaction_Inquiry_Document windows.

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

0 Comments on “#GPPT Setting Default Sorts for Inquiry Windows

Leave a Reply