Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Text from the Salutation field and from the Suffix field is not added to the Full Name field of a contact form in Microsoft Dynamics CRM


View products that this article applies to.

Symptoms

Consider the following scenario. You add the Salutation field and the Suffix field to the contact form in Microsoft Dynamics CRM. You then create a contact that includes text that is in the new fields. However, the text from the Salutation field and from the Suffix field is not added to the Full Name field of the contact.

↑ Back to the top


Cause

This issue occurs in Microsoft Dynamics CRM because the Full Name field is populated by using the values from only the following fields:
  • First Name
  • Middle Name
  • Last Name

↑ Back to the top


Workaround

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

  1. In Microsoft Dynamics CRM, click Settings, click Customization, and then click Customize Entities.
  2. Double-click Contact, click Forms and Views, double-click Form, and then click Form Properties.
  3. On the Events tab, click OnSave, and then click Edit.
  4. On the Details tab, type the JScript code that you want to include in the OnSave event.
  5. 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.
  6. Click OK to close the Form Properties dialog box.
  7. Click Save and Close.
  8. 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

  1. Click Settings, click Customization, and then click Customize Entities.
  2. Double-click Contact, click Forms and Views, double-click Quick Find Active Contacts, and then click Add View Columns.
  3. Click to select the check box for the custom Full Name field, and then click OK.
  4. Click Add Find Columns, click to select the check box for the custom Full Name field, and then click OK.
  5. Click Save and Close.
  6. On the "Entity: Contact" form, click Actions, and then click Publish.

↑ Back to the top


Keywords: kbmbsservice, kbmbscrmonline, kbmbscrm40, kbmbsjscript, kbtshoot, kbmbscustomization, kbmbsmigrate, kbprb, kbfreshness2008, KB915360

↑ Back to the top

Article Info
Article ID : 915360
Revision : 4
Created on : 12/29/2010
Published on : 12/29/2010
Exists online : False
Views : 498