How to make a field conditionally required in Microsoft Dynamics GP 9.0

Applies to: Visual Studio Tools for Microsoft Dynamics GP Software Development KitVisual Studio Tools for Microsoft Dynamics GP Runtime

INTRODUCTION

This article discusses a customization that can be used to make a field conditionally required in Microsoft Dynamics GP 9.0. When you make this customization, the User Defined 1 field must be set to a value if the customer is on hold.

MORE INFORMATION

The following code uses a ValidateBeforeOriginal event on the SaveRecord field instead of on the Save button. The SaveRecord field is selected because the SaveRecord event is called by the Customer Maintenance window from multiple locations. The SaveRecord event is always invoked when you save a record in this window.

The following code is the C# code for Visual Studio Tools in Microsoft Dynamics GP.
using System; using System.Collections.Generic; using System.Text; using Microsoft.Dexterity.Bridge; using Microsoft.Dexterity.Applications; using Microsoft.Dexterity.Applications.DynamicsDictionary; using System.Windows.Forms; namespace CustomerSaveTest { public class GPAddIn : IDexterityAddIn { //Declare a static variable that has an instance of the Customer Maintenance window. static Microsoft.Dexterity.Applications.DynamicsDictionary.RmCustomerMaintenanceForm.RmCustomerMaintenanceWindow cust = Microsoft.Dexterity.Applications.Dynamics.Forms.RmCustomerMaintenance.RmCustomerMaintenance; public void Initialize() { //Declare an event handler that will run before Microsoft Dynamics GP saves the customer record. cust.SaveRecord.ValidateBeforeOriginal += new System.ComponentModel.CancelEventHandler(SaveRecord_ValidateBeforeOriginal); } void SaveRecord_ValidateBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e) { //Implement the following business logic: If the customer is on hold, a reason must be entered in the "User Defined 1" field. if (cust.Hold == true && cust.UserDefined1.Value == "") { MessageBox.Show("For customers on hold, User Defined 1 is required."); //Cancel the Save event. e.Cancel = true; cust.UserDefined1.Focus(); } } } }
The following code is the code for Microsoft Visual Basic .NET.
Imports System Imports System.Collections.Generic Imports System.Text Imports Microsoft.Dexterity.Bridge Imports Microsoft.Dexterity.Applications Imports Microsoft.Dexterity.Applications.DynamicsDictionary Imports System.Windows.Forms Namespace ButtonEventTest Public Class GPAddIn Implements IDexterityAddIn ' IDexterityAddIn interfac                                                                                                  
This code typically works correctly. But, in some cases, the code clears the window without saving the record. The SaveRecord field acts as a flag. If the SaveRecord event is canceled, the record is not saved. But the flag is still set from when the previous customer was successfully saved. If this scenario occurs, use Modifier in Microsoft Dynamics GP to save the record. To do this, follow these steps:
1. Open the Customer Maintenance window. To do this, click Cards , point to Sales , and then click Customer .
2. Click Tools , point to Customize , and then click Modify Current Window . The "Window:RM_Customer_Maintenance" window is now displayed in Modifier.
3. Click Layout , and then click Show Field Names .
4. Click Layout , and then click Show Invisible Fields .
5. In the "Window:RM_Customer_Maintenance" window, click the Save Record field.
6. Click Layout , and then click Properties .
7. In the Properties dialog box, double-click the SaveOnRestart field to change the value from True to False .
8. To return to Microsoft Dynamics GP, click File , and then click Microsoft Dynamics GP . Click Save when you are prompted to save the changes.
9.

Assign security permissions to the modified version of the Customer Maintenance window. To do this, refer to Chapter 2 of the Advanced Security manual (AdvancedSecurity.pdf). By default, the Advanced Security manual is located in the following folder:

C:\Program Files\Microsoft Dynamics\GP\Documentation

 

DISCLAIMER 

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, THE RELIABILITY OR THE ACCURACY OF THE INFORMATION THAT IS CONTAINED IN THE DOCUMENTS AND THE RELATED GRAPHICS PUBLISHED ON THIS WEB SITE (THE “MATERIALS”) FOR ANY PURPOSE. 

THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON-INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS. 

APPLIES TO
Microsoft Dynamics GP 9.0
Developer Toolkit for Microsoft Dynamics GP
Visual Studio Tools for Microsoft Dynamics GP Runtime
Visual Studio Tools for Microsoft Dynamics GP Software Development Kit