Support Debugging Tool Customization #7 – Receiving Unit Cost Threshold Validation

| 10/08/2011 | 3 Comments

Based on a recent requests on the community, where the requirement was to validate that the unit cost entered in the Receiving Transaction Entry window is not more (or) less than a specified threshold of the Unit Cost entered in the respective PO line.

I have used Support Debugging Tool to handle this requirement. I have added this validation on the following windows.

  • Receivings Transaction Entry
  • Receivings Item Detail Entry
  • Purchasing Invoice Entry

Version Information

Dynamics GP : 11.0.1752 (SP2)

Support Debugging Tool : 11.00.0015

Screenshots of the Configuration

Trigger #1 – Resource Tab

This is a trigger on the Unit Cost Change – Before Original on the Receiving Transaction Entry scrolling window.

image

Trigger #1 – Actions Tab

If the validation fails, we will reject further execution of the GP script for the Unit Cost field, and we will set the old value to the Unit Cost field and leave the focus back to the Unit Cost field.

image

Trigger #1 – Customization Script

in string IN_OldValue;
in string IN_NewValue;
out boolean OUT_Condition;
 
local 'PO Number' 	l_PONo;
local 'Item Number'	l_ItemNo;
local Ord		l_Ord;
local 'Unit Cost'	l_UnitCostMin, l_UnitCostMax;
local currency		l_Threshold;
 
OUT_Condition = false;
 
set l_Threshold to 0.1;
 
if isopen(form POP_Receivings_Entry) then
	set l_PONo to 'PO Number' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
	set l_ItemNo to 'Item Number' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
	set l_Ord to 'PO Line Number' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
	clear table POP_POLine;
	set 'Item Number' of table POP_POLine to l_ItemNo;
	set 'PO Number' of table POP_POLine to l_PONo;
	set 'Ord' of table POP_POLine to l_Ord;
	get table POP_POLine by number 2;
	if err() = OKAY then
		set l_UnitCostMin to 'Unit Cost' of table POP_POLine;
		set l_UnitCostMin to l_UnitCostMin - round((l_UnitCostMin*l_Threshold),
			DECIMALRIGHT, ROUNDMODE_HALF_UP, 2);
		set l_UnitCostMax to 'Unit Cost' of table POP_POLine;
		set l_UnitCostMax to l_UnitCostMax + round((l_UnitCostMax*l_Threshold),
			DECIMALRIGHT, ROUNDMODE_HALF_UP, 2);
		if ('Unit Cost' of window 'Line_Scroll' of form 'POP_Receivings_Entry' < l_UnitCostMin or
			'Unit Cost' of window 'Line_Scroll' of form 'POP_Receivings_Entry' > l_UnitCostMax) then
			warning "The unit cost is beyond the threshold defined for this item in the purchase order!";
			OUT_Condition = true;
		end if;
	end if;
end if;

Trigger #2 – Resource Tab

This is a trigger on the Extended Cost Change – Before Original on the Receiving Transaction Entry Scrolling window.

image

Trigger #2 – Actions Tab

If the validation fails, we will reject further execution of the GP script for the Extended Cost field, and we will set the old value to the Extended Cost field and leave the focus back to the Extended Cost field.

image

Trigger#2 – Customization Script

in string IN_OldValue;
in string IN_NewValue;
out boolean OUT_Condition;
 
local 'PO Number' 		l_PONo;
local 'Item Number'		l_ItemNo;
local Ord			l_Ord;
local 'Unit Cost'		l_UnitCostMin, l_UnitCostMax, l_CalcUnitCost;
local 'Extended Cost'		l_ExtdCost;
local QTY			l_QtyShipped;
local currency			l_Threshold;
 
OUT_Condition = false;
 
set l_Threshold to 0.1;
 
if isopen(form POP_Receivings_Entry) then
	set l_PONo to 'PO Number' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
	set l_ItemNo to 'Item Number' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
	set l_Ord to 'PO Line Number' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
	clear table POP_POLine;
	set 'Item Number' of table POP_POLine to l_ItemNo;
	set 'PO Number' of table POP_POLine to l_PONo;
	set 'Ord' of table POP_POLine to l_Ord;
	get table POP_POLine by number 2;
	if err() = OKAY then
		set l_UnitCostMin to 'Unit Cost' of table POP_POLine;
		set l_UnitCostMin to l_UnitCostMin - (l_UnitCostMin*l_Threshold);
		set l_UnitCostMax to 'Unit Cost' of table POP_POLine;
		set l_UnitCostMax to l_UnitCostMax + (l_UnitCostMax*l_Threshold);
		set l_ExtdCost to 'Extended Cost' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
		set l_QtyShipped to 'QTY Shipped' of window 'Line_Scroll' of form 'POP_Receivings_Entry';
		set l_CalcUnitCost to round((l_ExtdCost/l_QtyShipped),
			DECIMALRIGHT, ROUNDMODE_HALF_UP, 2);
		if (l_CalcUnitCost < l_UnitCostMin or
			l_CalcUnitCost > l_UnitCostMax) then
			warning "The unit cost is beyond the threshold defined for this item in the purchase order!";
			OUT_Condition = true;
		end if;
	end if;
end if;

Assumptions

For the  purpose of this customization, I have assumed a threshold of 10% (i.e.) the unit cost entered in the Receiving Transaction Entry for a line can be more or less by 10% but not beyond. You can change this to any other value needed based on business needs. You can even have the threshold defined in a custom table and fetch it from the table.

Things To Remember

The above code example is for the Receiving Transactions Entry window. However, we will also have to replicate a similar logic on the Receivings Item Detail Entry window for both the Unit Cost and Extended Cost field, since the user can enter/change the unit cost and extended cost on this window as well.

Configuration File Location

You can download the configuration for this requirement here. This file has the triggers for both the windows mentioned above.

Reference

Take a look at the article below which summarizes the usage of Support Debugging Tool with some real life examples. Great compilation by David! http://blogs.msdn.com/b/developingfordynamicsgp/archive/2011/08/05/using-the-support-debugging-tool-with-real-life-examples.aspx

Hope this helps the community…

Until next post!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Tags: , , , , , , , ,

Category: Customizations, Dynamics, Great Plains, Support Debugging Tool

About the Author ()