#GPPT Making Reason Code on Inventory Transactions Required

David Meego - Click for blog homepageThis is the seventh article in the series on making window fields required. If you have not yet read the introduction article to the series, please read that first:

This example uses GP Power Tools to make the Reason Code field on the Item Transfer Entry Scrolling window required. This article was prompted by a support request that came in today.

Both the Item Transaction Entry and Item Transfer Entry windows are using the required() function on the scrolling window change (save) script and so using the Modifier to change the Reason Code field’s Object >> Required property to True does work to force that field to be entered.

Using Modifier does mean that you will need to change the security setting in the Modified Alternate Forms and Reports window to point to the Modified version of the inventory transaction window.

This article will show you some alternatives without Modifier using GP Power Tools. Let’s start by creating a Project:

  1. Open the Project Setup window. Click clear if an existing current project is displayed.
  2. Enter the Project ID: IV_TRX_REASON_CODE
  3. Enter the Project Description: Make Inventory Transaction Reason Code Required
  4. Enter the Open Form (optional) for testing, in the 0: Microsoft Dynamics GP product, IV_Transfer_Entry
  5. Mark the project as your Current Project.
  6. Press Ctrl-S to save and continue (or Options Menu >> Save and continue).

No Code Method using Form Control

Because the required() function has been used by the original code (as it should be), we can use Form Control to add the required field without any code.

  1. From the Project, Click Add >> Form Control Setup.
  2. Enter the Form Control ID: IV_TRX_REASON_CODE and Form Control Name: Make Inventory Transaction Reason Code Required.
  3. Double click on the Base Settings Resource node and set it to Form Mode: Exact and Form Name: IV_Transfer_Entry.
  4. Optional: If you want to apply to Item Transaction Entry as well, check the Allow Multiple Resources (OR mode) checkbox.
  5. Click OK to close the window.
  6. Optional: If you want to apply to Item Transaction Entry as well, click the Plus sign to Add another Resource node, and set it for Form Mode: Exact and Form Name: IV_Transaction_Entry and check the Allow Multiple Resources (OR mode) checkbox. Then click OK to close the window.
  7. Click the Plus sign to Add the Field Rule >> Add Required Field. Click OK as no changes are needed for the rule itself.
  8. Double click on the Resource node and set Field Mode: Exact, Field Name: Reason Code and click OK.
  9. Click Save to save the Form Control ID and close the window.

That’s all, you can now test the Inventory transaction windows, and the Reason Code is now required. The advantages of Form Control are that we can apply the change to multiple windows with a single Form Control ID and that we did not need to write any code.

Setting Required Flag Method using Trigger Setup

It is possible to achieve the exact same customization manually using a trigger on each window.

  1. From the Project, Click Add >> Trigger Setup.
  2. Enter the Trigger ID: IV_TRX_REASON_CODE1 and Trigger Description: Make Item Transfer Entry Reason Code Required.
  3. Check Start Trigger Automatically checkbox.
  4. Set Trigger Type: Focus Event, Trigger Event, Window Pre, Trigger Attach: After Original.
  5. On the Resource Tab, select Product: 0: Microsoft Dynamics GP, Form Name: IV_Transfer_Entry, Window Name: IV_Transfer_Entry.
  6. On the Script Tab, add the Field_SetBooleanProperty() command as shown below to set the Required Property to True.
  7. Click Save.
out boolean OUT_Condition;

OUT_Condition = false;

if isopen(form IV_Transfer_Entry) then
	Field_SetBooleanProperty('Reason Code' of window 'IV_Transfer_Scroll' of form 'IV_Transfer_Entry', FIELD_PROP_REQUIRED, true);	
	OUT_Condition = true;
end if;

You can repeat the steps for IV_Transaction_Entry using Trigger ID: IV_TRX_REASON_CODE2 and Trigger Description: Make Item Transaction Entry Reason Code Required.

Use the Open Form prompt hyperlink to open the window to test and say yes when asked to start the triggers and now the fields are required. This is achieving the same results as Form Control but using triggers and scripts.

Checking Field Method using Trigger Setup

The last method is one that can work when the required() function has not been used in the original code to stop a scrolling window saving when a field is empty. Using the previous methods is preferred as it allows the existing code to work and just programmatically marks the field as required.

This time we will use a focus trigger before the scrolling window change (save) event and cause it to be aborted if the additional required field is empty.

  1. From the Project, Click Add >> Trigger Setup.
  2. Enter the Trigger ID: IV_TRX_REASON_CODE3 and Trigger Description: Force Item Transfer Entry Reason Code to be entered.
  3. Check Start Trigger Automatically checkbox.
  4. Set Trigger Type: Focus Event, Trigger Event, Scroll Change, Trigger Attach: Before Original.
  5. On the Resource Tab, select Product: 0: Microsoft Dynamics GP, Form Name: IV_Transfer_Entry, Window Name: IV_Transfer_Scroll.
  6. On the Actions Tab, check the Issue Reject Script checkbox.
  7. On the Script Tab, edit the script as shown below to check if the field is empty and then set the focus to the field and restart it. Then display the required field warning dialog and by setting OUT_Condition = true we make the selected actions (Reject Script) happen.
  8. Click Save.
out boolean OUT_Condition;

OUT_Condition = false;

if isopen(form IV_Transfer_Entry) then
	if empty('Reason Code' of window 'IV_Transfer_Scroll' of form 'IV_Transfer_Entry') then
		focus 'Reason Code' of window 'IV_Transfer_Scroll' of form 'IV_Transfer_Entry';
		restart field;
		call Warning_Dialog,2351;
		OUT_Condition = true;
	end if;
end if;

You can repeat the steps for IV_Transaction_Entry using Trigger ID: IV_TRX_REASON_CODE4 and Trigger Description: Force Item Transaction Entry Reason Code to be entered.

You can add a message to the Action tab if you want your own wording rather than calling the standard Warning_Dialog command. If you add a message, check, Display Message to screen using system dialog, Display Message to screen using simple dialog instead of text dialog, leave Dialog type as Warning and enter the message in the Dialog Message or as a Message ID.

Conclusion

All four methods (Modifier and 3 GPPT) work and show that there is always more than one solution to any given problem. Here is the project setup window:

Note: Only have one of the methods enabled at a time. There is no need to have more than one method active as this could cause the warning dialog to be displayed more than once.

Downloading and Installing

Download the example code, import using the Project Setup window (without any project showing, select the path to the xml file and click Import):

Form Control will be enabled immediately. The triggers (if not disabled) will be active on next login or after switching companies, or you can start the triggers manually from the Project Setup window.

More Information

For more information see:

Hope you find this example useful.

David

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

Leave a Reply