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

This article has been archived. It is offered "as is" and will no longer be updated.
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 SystemImports System.Collections.GenericImports System.TextImports Microsoft.Dexterity.BridgeImports Microsoft.Dexterity.ApplicationsImports Microsoft.Dexterity.Applications.DynamicsDictionaryImports System.Windows.Forms  Namespace ButtonEventTest    Public Class GPAddIn	 Implements IDexterityAddIn        ' IDexterityAddIn interface         static Microsoft.Dexterity.Applications.DynamicsDictionary.RmCustomerMaintenanceForm.RmCustomerMaintenanceWindow cust =            Microsoft.Dexterity.Applications.Dynamics.Forms.RmCustomerMaintenance.RmCustomerMaintenance         Public  Sub Initialize()	    AddHandler cust.SaveRecord.ValidateBeforeOriginal, AddressOf SaveRecord_ValidateBeforeOriginal                   End Sub        Private  Sub SaveRecord_ValidateBeforeOriginal(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)            'Implement business logic: If the Customer is on hold, we must have a reason entered in User Defined 1            If cust.Hold = True And cust.UserDefined1.Value = "" Then                MessageBox.Show("You have to enter a value for User Defined 1 before saving.")                e.Cancel = True                               cust.UserDefined1.Focus()            End If        End Sub  End ClassEnd Namespace
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

Article ID: 934695 - Last Review: 01/15/2015 08:42:55 - Revision: 4.0

  • 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
  • kbnosurvey kbarchive kbexpertiseadvanced kbexpertiseinter kbinfo kbmbsmigrate kbhowto KB934695