To work around this issue, you must create a custom field
for the full name on the Microsoft Dynamics CRM contact form. The custom field can be
populated by using the OnSave form event of the contact form, or by using any
one of the following business logic extensions:
- Pre-create
- Post-create
- Pre-update
- Post-update
The value of the custom field can be created based on the
values of the default name fields, such as the following fields:
- Salutation
- First Name
- Middle Name (or Middle Initial)
- Last Name
- Suffix
By using the values of the default name fields, you can format
the custom field as required within the environment. You can format the custom
field to resemble any of the following examples:
- Dr. Jane Smith, PhD
- Dr. Jane R. Smith, PhD
- Dr. Jane Regan Smith
- Smith, Jane Regan, PhD
Notes- This article contains sample JScript code to add to the
OnSave form event of the contact form to populate the custom Full
Name field. For more information about the Pre-create, the
Post-create, the Pre-update, and the Post-update business logic extensions,
visit the following Microsoft Web site:
- After you create the custom field, additional steps are
required to show the custom field on existing reports or in other areas of
Microsoft Dynamics CRM.
- If you want to search on the custom field in a Microsoft
Dynamics CRM view, the custom field must be added to the view on the Contact entity. For
example, you may add the custom field as a Find column to the
Quick Full Name view.
- The following conditions must be true before you implement this solution:
- You must create the custom field before you can add the
sample code to the OnSave form event of the contact form.
- After you add the custom field to the form, you can add
JScript to the OnSave form event to populate the custom field.
- All fields that you use to populate the custom field
must be on the contact form.
- The custom field that is used in the sample code in this
article has the following name:
new_completefname
Sample code for the OnSave form event
Microsoft
provides programming examples for illustration only, without warranty either
expressed or implied. This includes, but is not limited to, the implied
warranties of merchantability or fitness for a particular purpose. This article
assumes that you are familiar with the programming language that is being
demonstrated and with the tools that are used to create and to debug
procedures. Microsoft support engineers can help explain the functionality of a
particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific requirements.
Example 1
This example populates the custom
Full Name
field by using the values of the
Salutation field, the
First Name field, the
Middle Name field, the
Last Name field, and the
Suffix field. Use
the following sample code to combine the values.
/* Obtain the required values. */
var sal = crmForm.all.salutation.DataValue;
var firstName = crmForm.all.firstname.DataValue;
var middleName = crmForm.all.middlename.DataValue;
var lastName = crmForm.all.lastname.DataValue;
var suf = crmForm.all.suffix.DataValue;
/* Create a variable to store the complete full name. */
var fullName = "";
/* Create an array to set the order of the full name. */
var fName = [sal, firstName, middleName, lastName, suf];
/* Create a second array to determine whether the associated name in the
fName array should be included in the complete full name. */
var includeFName = [true, true, true, true, true];
/* Create the value for the full name. */
for(var i = 0; i<fName.length; i++)
{
if(fName[i] == null)
{
fName[i] = "";
includeFName[i] = false;
}
if(includeFName[i] == true)
{
fullName = fullName + fName[i] + " ";
}
}
/* Assign the value of the fullName variable to the custom Full Name field. */
crmForm.all.new_completefname.DataValue = fullName;
Example 2
This example populates the custom
Full Name
field by using the values of the
Salutation field, the
Last Name field, the
First Name field, the
Middle Name field, and the
Suffix field. Use
the following sample code to combine the values.
/* Obtain the required values. */
var sal = crmForm.all.salutation.DataValue;
var firstName = crmForm.all.firstname.DataValue;
var middleName = crmForm.all.middlename.DataValue;
var lastName = crmForm.all.lastname.DataValue;
var suf = crmForm.all.suffix.DataValue;
/* Check to see whether the middleName variable is null before you add a comma. */
if(middleName != null)
{
middleName = middleName+",";
}
/* Check to see whether the lastName variable is null before you add a comma. */
if(lastName != null)
{
lastName = lastName+",";
}
if(suf == null)
{
middleName = crmForm.all.middlename.DataValue;
}
/* Create a variable to store the complete full name. */
var fullName = "";
/* Create an array to set the order of the full name. */
var fName = [lastName, sal, firstName, middleName, suf];
/* Create a second array to determine whether the associated name in the
fName array should be included in the complete full name. */
var includeFName = [true, true, true, true, true];
/* Create the value for the full name. */
for(var i = 0; i<fName.length; i++)
{
if((fName[i] == null) || (fName[i] == ","))
{
fName[i] = "";
includeFName[i] = false;
}
if(includeFName[i] == true)
{
fullName = fullName + fName[i] + " ";
}
}
/* Assign the value of the fullName variable to the custom Full Name field. */
crmForm.all.new_completefname.DataValue = fullName;
How to add JScript to the OnSave event of the contact form
- In Microsoft Dynamics CRM, click Settings, click
Customization, and then click Customize
Entities.
- Double-click Contact, click Forms
and Views, double-click Form, and then click
Form Properties.
- On the Events tab, click
OnSave, and then click Edit.
- On the Details tab, type the JScript code
that you want to include in the OnSave event.
- On the Dependencies tab in the
Dependent fields box, add the fields that you use to populate
the custom Full Name field. Then click
OK.
- Click OK to close the Form
Properties dialog box.
- Click Save and Close.
- On the "Entity: Contact" form, click
Actions, and then click Publish.
How to add the custom Full Name field to the "Quick Find View for Contacts" form
- Click Settings, click
Customization, and then click Customize
Entities.
- Double-click Contact, click Forms
and Views, double-click Quick Find Active Contacts,
and then click Add View Columns.
- Click to select the check box for the custom Full
Name field, and then click OK.
- Click Add Find Columns, click to select
the check box for the custom Full Name field, and then click
OK.
- Click Save and Close.
- On the "Entity: Contact" form, click
Actions, and then click Publish.