Categorized | Featured

avatar

Dexterity Focus Triggers in Dynamics GP

The Dexterity Integration tools include several object triggers. These triggers allow Dynamics GP to respond to certain events that occur within the application. The Dexterity triggers reside in the developer’s custom data dictionary. The trigger must be registered with the Dexterity.exe runtime engine; the developer registers the trigger in the Startup Global Script.

To create the Startup Global Script, open the custom data dictionary using Dexterity and click on the “Scripts Resource” folder; then click the “New…” button, and a blank Global Script window will open.

8216-1

Next, change the Procedure name to “Startup,” then select “System for the Core.”

8216-2

In our example, we are looking to create a Field Focus trigger. The Field Focus triggers are activated by focus events occurring within the application.

You can create focus triggers that respond to the following types of objects and focus events:

8216-3

 

Focus triggers require the developer to identify the object activating the trigger, the event to activate and the Global Script to run in response to the focus event. The fields on Dynamics GP windows have three focus events, but the push-button fields only activate triggers for the change focus event.

8216-4

In our example, we will trigger on the event when the GP user clicks on the push button called “Post Button” on the Sales Batch Entry window. The Global Script BKD_Update_Sales_Dist_Before_Post will execute before the standard GP code runs.

8216-5

 

Global Script

BKD_Update_Sales_Dist_Before_Post

<div style=”background-color: #f4f4f4; border: 1px solid gray; color: #3333ff; font-size-adjust: none; font-stretch: normal; font: 12px/12px Georgia, Garamond, Serif; height: 107px; overflow: scroll; width: 640px;”>

<pre>

local long l_item_default_actindx;

local integer virtual_key;

local long l_sequence_number;

local string l_batchnumber;

l_sequence_number = 300000;

open form Progress_Control;

‘(L) File Processed’ of window Progress_Window of form Progress_Control = “Updating SOP Sales Distributions”;

‘(L) Record Processed’ of window Progress_Window of form Progress_Control = “Please Wait……”;

‘(L) Percent Complete’ of window Progress_Window of form Progress_Control = 100;

 

l_batchnumber = ‘Batch Number’ of window SOP_Batch_Entry of form SOP_Batch_Entry;

 

{*** Begin Remove All Sales Distributions for each SOP Invoice in this Batch **}

range clear table BKD_SOP_HDR_WORK;

‘Batch Source’ of table BKD_SOP_HDR_WORK = “Sales Entry”;

‘Batch Number’ of table BKD_SOP_HDR_WORK = ‘Batch Number’ of window SOP_Batch_Entry of form SOP_Batch_Entry;

‘SOP Type’ of table BKD_SOP_HDR_WORK = 3;

clear field ‘SOP Number’ of table BKD_SOP_HDR_WORK;

range start  table BKD_SOP_HDR_WORK by number 4;

‘Batch Source’ of table BKD_SOP_HDR_WORK = “Sales Entry”;

‘Batch Number’ of table BKD_SOP_HDR_WORK = ‘Batch Number’ of window SOP_Batch_Entry of form SOP_Batch_Entry;

‘SOP Type’ of table BKD_SOP_HDR_WORK = 3;

fill ‘SOP Number’ of table BKD_SOP_HDR_WORK;

range end  table BKD_SOP_HDR_WORK by number 4;

get first table BKD_SOP_HDR_WORK by number 4;

while err() <> EOF do

range clear table BKD_SOP_Distribution_WORK_HIST;

‘SOP Type’ of table BKD_SOP_Distribution_WORK_HIST = ‘SOP Type’ of table BKD_SOP_HDR_WORK;

‘SOP Number’ of table BKD_SOP_Distribution_WORK_HIST = ‘SOP Number’ of table BKD_SOP_HDR_WORK;

‘Distribution Type’ of table BKD_SOP_Distribution_WORK_HIST = 1;

clear field ‘Account Index’ of table BKD_SOP_Distribution_WORK_HIST;

range start table BKD_SOP_Distribution_WORK_HIST by number 2;

‘SOP Type’ of table BKD_SOP_Distribution_WORK_HIST = ‘SOP Type’ of table BKD_SOP_HDR_WORK;

‘SOP Number’ of table BKD_SOP_Distribution_WORK_HIST = ‘SOP Number’ of table BKD_SOP_HDR_WORK;

‘Distribution Type’ of table BKD_SOP_Distribution_WORK_HIST = 1;

fill ‘Account Index’ of table BKD_SOP_Distribution_WORK_HIST;

range end table BKD_SOP_Distribution_WORK_HIST by number 2;

remove range table BKD_SOP_Distribution_WORK_HIST;

get next table BKD_SOP_HDR_WORK by number 4;

end while;

{*** End Remove All Sales Distributions for each SOP Invoice in this Batch **}

assign virtual_key as key for table BKD_SOP_LINE_WORK with

KEY_OPTION_ALLOW_DUPLICATES using ‘SOP Type’ of table BKD_SOP_LINE_WORK,

‘SOP Number’ of table BKD_SOP_LINE_WORK,

‘Item Number’ of table BKD_SOP_LINE_WORK with

KEY_SEGMENT_OPTION_DESCENDING;

clear table BKD_Proj_Account;

release table BKD_Proj_Account;

get first table BKD_Proj_Account by number 1;

while err() <> EOF do

range clear table BKD_SOP_LINE_WORK;

‘SOP Type’ of table BKD_SOP_LINE_WORK = 3;

clear ‘SOP Number’ of table BKD_SOP_LINE_WORK;

‘Item Number’ of table BKD_SOP_LINE_WORK = ‘Item Number’ of table BKD_Proj_Account;

range start table BKD_SOP_LINE_WORK by number virtual_key;

‘SOP Type’ of table BKD_SOP_LINE_WORK = 3;

fill ‘SOP Number’ of table BKD_SOP_LINE_WORK;

‘Item Number’ of table BKD_SOP_LINE_WORK = ‘Item Number’ of table BKD_Proj_Account;

range end table BKD_SOP_LINE_WORK by number virtual_key;

get first table BKD_SOP_LINE_WORK by number virtual_key;

while err() <> EOF do

if ‘Item Number’ of table BKD_SOP_LINE_WORK = ‘Item Number’ of table BKD_Proj_Account then

clear table BKD_SOP_Distribution_WORK_HIST;

release table BKD_SOP_Distribution_WORK_HIST;

set ‘SOP Type’ of table BKD_SOP_Distribution_WORK_HIST to ‘SOP Type’ of table BKD_SOP_LINE_WORK;

set ‘SOP Number’ of table BKD_SOP_Distribution_WORK_HIST to ‘SOP Number’ of table BKD_SOP_LINE_WORK;

set ‘Sequence Number’ of table BKD_SOP_Distribution_WORK_HIST to l_sequence_number;

change table BKD_SOP_Distribution_WORK_HIST by number 1;

set ‘Distribution Type’ of table BKD_SOP_Distribution_WORK_HIST to 1;

set ‘Account Index’ of table BKD_SOP_Distribution_WORK_HIST to ‘Account Index’ of table BKD_Proj_Account;

if ‘Extended Price’ of table BKD_SOP_LINE_WORK > 0.00 then {** Positive Quantity Debit Amount Credit to Sales **}

set ‘Credit Amount’ of table BKD_SOP_Distribution_WORK_HIST to ‘Credit Amount’ of table BKD_SOP_Distribution_WORK_HIST

+ ‘Extended Price’ of table BKD_SOP_LINE_WORK;

set ‘Originating Credit Amount’ of table BKD_SOP_Distribution_WORK_HIST to

‘Originating Credit Amount’ of table BKD_SOP_Distribution_WORK_HIST + ‘Extended Price’ of table BKD_SOP_LINE_WORK;

end if;

if ‘Extended Price’ of table BKD_SOP_LINE_WORK < 0.00 then {** Negative Quantity Credit Amount Debit to Sales **}

set ‘Debit Amount’ of table BKD_SOP_Distribution_WORK_HIST to ‘Debit Amount’ of table BKD_SOP_Distribution_WORK_HIST

+ (‘Extended Price’ of table BKD_SOP_LINE_WORK * -1);

set ‘Originating Debit Amount’ of table BKD_SOP_Distribution_WORK_HIST to

‘Originating Debit Amount’ of table BKD_SOP_Distribution_WORK_HIST + (‘Extended Price’ of table BKD_SOP_LINE_WORK * -1);

end if;

set ‘Currency Index’ of table BKD_SOP_Distribution_WORK_HIST to 1007;

{** Begin Find out Which Batch }

clear table BKD_SOP_HDR_WORK;

release table BKD_SOP_HDR_WORK;

set ‘SOP Number’ of table BKD_SOP_HDR_WORK to ‘SOP Number’ of table BKD_SOP_Distribution_WORK_HIST;

set ‘SOP Type’ of table BKD_SOP_HDR_WORK to ‘SOP Type’ of table BKD_SOP_Distribution_WORK_HIST;

get table BKD_SOP_HDR_WORK by number 1;

if ‘Batch Number’ of table BKD_SOP_HDR_WORK = l_batchnumber then

save table BKD_SOP_Distribution_WORK_HIST;

l_sequence_number = l_sequence_number + 16384;

end if;

{** End Find out Which Batch }

release table BKD_SOP_Distribution_WORK_HIST;

end if;

get next table BKD_SOP_LINE_WORK by number virtual_key;

end while;

get next table BKD_Proj_Account by number 1;{BKD_Proj_Account}

end while;

close form Progress_Control;

</pre></div>

The example code above removes the Sales Distributions for all of the SOP Invoices associated with the batch number on the Sales Batch Entry window. Next, the Sales Distributions are re-created using a companion table. Once all the Sales Distributions are added, the standard GP code will run to complete the posting process.

One important thing to consider when developing focus triggers is the table buffers, which are attached to the form when the trigger is activated. The table buffers are available until the form is closed. The table buffers are in the same state as the last time the last trigger Global Script accessed them. Since there could be other third-party applications accessing the same table buffer, you may need to clean up any table buffers before your Global Script completes executing.

After completing your customizations, you will need to create your chunk file to install the changes into your GP client.

This post was written by:

Steve is the leader of custom application development efforts for the BKD Technologies Microsoft Dynamics GP product team. He has more than 21 years of experience as an IT system administrator for Microsoft Windows, UNIX and Novell environments, including development and implementation of turnkey systems and custom applications. Steve is a Certified NetWare Administrator, Certified NetWare Engineer, Certified Software Engineer – Dexterity, Certified Integration Developer – Dexterity and Microsoft Great Plains Modifier with Visual Basic for Applications.

Leave a Reply


Dynamics GP Categories