locked
How can I Update fullname in COntact in CRM RRS feed

  • Question

  • I want format of fullname like Title + First Name + Last Name.but this type of format is not avalilable in System settings.so,I just want to update fullname not first name or last name.How can I achieve this requirements.
    Monday, August 12, 2013 9:50 AM

All replies

  • Hi Kartik,

    Fullname is auto set by CRM as firstname+lastname. We cannot override fullname.

    If you want to format the fullname as title then you can use below approach,

    Add two new custom fields in contact 1. new_title 2. new_firstname. These fields will be added on the form to accept data from user. Also firstname(system field) will be hidden on the form. Then write a custom code to set firstname(system field) as new_title+new_firstname.

    Then CRM will set the fullname as firstname(new_title+new_firstname) + lastname.

    Let me know if this works for you.

    Kalim Khan

    Monday, August 12, 2013 10:22 AM
  • Or You can store title and first name in the first name field.

    Regards Faisal

    Monday, August 12, 2013 10:26 AM
  • @KalimK=Yes Thanks for the Reply.I thought this solution before but the Issue is that client dont want to change firstname(system field) because there are lots of workflow and view and Report based on the field firstname(system field).They are not ready to add any new field and dont want change in firstname(systemfield).
    Monday, August 12, 2013 11:19 AM
  • @Faisal Fiaz=Thanks for the reply but we dont want to change the firstname just change the fullname like Title+First Name+Last Name


    Monday, August 12, 2013 11:20 AM
  • You will have to do something to meet your requirement. Not making any change will not produce any result.

    Regards Faisal

    Monday, August 12, 2013 1:47 PM
  • If you use a plugin you can override the CRM format. Simply write a pre-state plugin that takes the salutation, firstname, and lastname and updates the fullname.

    I've written a sample plugin which proves this method works. It all uses the out of the box CRM fields, the only addition is the plugin:

            /// <summary>
            /// Override the CRM Fullname format on a contact to be "Salutation First Name Last Name".
            /// 
            /// Plugin steps:
            /// create - contact - pre-operation - synchronous
            /// update - contact - pre-operation - synchronous - filtering attributes: firstname, lastname, salutation
            /// </summary>
            /// <param name="target">context.InputParameters["Target"]</param>
            /// <param name="context">IPluginExecutionContext</param>
            /// <param name="service">IOrganizationService</param>
            private void SetFullName(Entity target, IPluginExecutionContext context, IOrganizationService service)
            {
                string salutation = "";
                string firstName = "";
                string lastName = "";
    
                //if it's update get the values as they may not be in target
                if (context.MessageName.Equals("update", StringComparison.InvariantCultureIgnoreCase))
                {
                    Entity contact = service.Retrieve(target.LogicalName, target.Id, new ColumnSet("salutation", "firstname", "lastname"));
    
                    //get the current values first, then if a newer value is in target we'll use that
                    if (contact.Contains("salutation")) { salutation = (string)contact["salutation"]; }
                    if (contact.Contains("firstname")) { firstName = (string)contact["firstname"]; }
                    if (contact.Contains("lastname")) { lastName = (string)contact["lastname"]; }
                }
    
                //if target has a newer value take that, otherwise (on update) the current values will be used
                if (target.Contains("salutation")) { salutation = (string)target["salutation"]; }
                if (target.Contains("firstname")) { firstName = (string)target["firstname"]; }
                if (target.Contains("lastname")) { lastName = (string)target["lastname"]; }
    
                //join the salutation, first name, and last name (ignoring nulls)
                string fullName = string.Join(" ", new string[] { salutation, firstName, lastName }
                    .Where(a => !string.IsNullOrWhiteSpace(a)));
    
                //update target, overriding whatever CRM sets
                target["fullname"] = fullName;
            }

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    • Proposed as answer by Anil_Ch Tuesday, August 13, 2013 10:09 AM
    Tuesday, August 13, 2013 9:10 AM