CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom Field in Individual Display Name Format
Pages: [1]

Author Topic: Custom Field in Individual Display Name Format  (Read 2406 times)

swettling

  • Guest
Custom Field in Individual Display Name Format
September 27, 2010, 10:42:55 am
It's awesome that I can reconfigure the display name format using standard contact fields.  However, we would like to be able to add a custom field, also.  We have a custom field called "Designation" (custom_154) that we want to append at the end of the display name.

I can't figure out if this is possible.  It's pretty important as the group I am working with consists of doctors, many of which have multiple designations.  We're just giving them a field to fill in whatever designations they have and then use it as part of the display name.

Is this possible?

I will also add that a "designation" field would be a nice addition to future versions of the application so someone can be Dr. Clyde Smith, III, MD

Thanks

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Custom Field in Individual Display Name Format
September 27, 2010, 10:52:49 am
Simple approach would be to consider re-purposing the Suffix field if you can leave without the 'III' in your example. You can use the Word Replacement admin feature to re-label Suffix -> Designation, and re-populate the options for Suffix with the designations you use. Those values will automatically be appended to display names.
Protect your investment in CiviCRM by  becoming a Member!

swettling

  • Guest
Re: Custom Field in Individual Display Name Format
September 27, 2010, 11:48:34 am
I thought about this, but there are a LOT of possible combinations and the suffix field uses a reference. It's not just a text field that I can put stuff into.  I wish it was and I wouldn't have this problem.  I also though about repurposing the nickname field, but they use that also.

I know there's a good chance I'll have to modify some code, and that's fine, but if there's a more elegant way to do this, I would like to know of it.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Custom Field in Individual Display Name Format
September 27, 2010, 04:46:26 pm
We added the ability to customize the Individual display name via tokens in 3.2:
http://issues.civicrm.org/jira/browse/CRM-6137

You can see the interface for this from CiviCRM > Administer > Global Settings > Site Preferences ... Individual Display Name Format.

However, I just did a quick test and custom field token aren't supported (yet) in this mechanism.

So, three possible approaches for you...
1. (preferred) Investigate and submit a patch to add support for custom field tokens to this feature. We can help you get started w/ this on IRC.

2. Use the "post" hook to modify the display_name whenever a contact record is added or updated in the DB

3. Use a MySQL trigger.
Protect your investment in CiviCRM by  becoming a Member!

swettling

  • Guest
Re: Custom Field in Individual Display Name Format
September 27, 2010, 08:41:08 pm
Dave,

Thanks for the input.  You clarified the issue well enough for me for now.  Hooks or triggers are probably where we're heading for now.  Will be great when the ability to do this is build in.  Seems like it's so close.

Cheers,

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Custom Field in Individual Display Name Format
September 27, 2010, 10:43:44 pm
It is pretty close - would be great if you were up for doing the patch instead of the work-around.
Protect your investment in CiviCRM by  becoming a Member!

smksites.com

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 4.3.7
  • CMS version: Drupal
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Custom Field in Individual Display Name Format
March 20, 2014, 06:25:35 pm
I was asked to do this exact thing for a client.  I ending up trying hooks for tokens, didn't work.  The final solution was just to modify the core.  Before doing this make sure you backup each file.

Here is this fix for version 4.3.7 drupal 7.x

Add a new field to the civicrm_contact table named credential_name varchar 255

go to your module folder
Download file the following files 
sites/modules/all/civicrm/crm/contact/DAO/contact.php

add the following code to the page
line 146 public $credential_name;
line 964 'credential_name' => array(
          'name' => 'credential_name',
          'type' => CRM_Utils_Type::T_STRING,
          'title' => ts('Credential') ,
          'maxlength' => 255,
          'size' => CRM_Utils_Type::BIG,
          'import' => true,
          'where' => 'civicrm_contact.credential_name',
          'headerPattern' => '/^credential|(c(redential\s)?name)$/i',
          'dataPattern' => '',
          'export' => true,
        ),

sites/modules/all/civicrm/templates/contact/form/inline/ContactName.tpl

Add code where you want field displayed
 <div class="crm-inline-edit-field">
      {$form.credential_name.label}<br />
      {$form.credential_name.html}
    </div>

sites/modules/all/civicrm/crm/contact/form/edit/individual.php
add the following code to the page
line 80 $form->addElement('text', 'credential_name', ts('Credentials'), $attributes['credential_name']);

sites/modules/all/civicrm/crm/utils/address.php
add the following code to the page
line 110 'contact.credential_name' => CRM_Utils_Array::value('credential_name', $fields),

Then log back into your site and go to your administrator > Custom data and Screens > display preferences
and set your individual name format to the following
{contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.credential_name}


Search for an individual and edit the display name add credentials and they will now show up for the display name
I also altered the display_name field in civicrm_contacts table to be varchar 255

Hope this of use to some people.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom Field in Individual Display Name Format

This forum was archived on 2017-11-26.