Answers.Body: <p>There's a <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/Address.php#L159" rel="nofollow noreferrer">place in the CiviCRM code</a> where all the possible contact tokens are defined - and they say which fields they correspond to.</p>
  
  <p>The line in question is:
  <code>'contact.contact_id' =&gt; CRM_Utils_Array::value('id', $fields),</code>
  which means, "populate the contact_id token from the <code>id</code> field passed to this function".</p>
  
  <p>That's no doubt correct in some instances - but in this instance, the data is stored in <code>contact_id</code>.  I was able to get the contact_id to work in <code>display_name</code> and <code>sort_name</code> by changing this line to:</p>
  
  <p><code>'contact.contact_id' =&gt; CRM_Utils_Array::value('id', $fields, CRM_Utils_Array::value('contact_id', $fields)),</code>.  </p>
  
  <p>This translates to, "populate the contact_id token from <code>id</code> if it exists, but <code>contact_id</code> if not".</p>
  
  <p>Whether you want to shepherd this change into upstream CiviCRM or not is up to you!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-04T18:09:19.660Z
Answers.LastActivityDate: 2019-01-04T18:09:19.660Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I have a client who wants to use the the contact id as an identifier in the Individual Sort Name Format. Basically they want to see "Smith, John (6548)" in search results because they want to use the ID to link to some paper files they are required to keep and they have a lot of contacts with identical names.</p>
  
  <p>At the bottom of Administer --> Customize Data and Screens --> Display Preferences, you can set the Individual Sort Name Format using tokens. However, when I insert</p>
  
  <p>{contact.last_name}{, }{contact.first_name}{ }{contact.contact_id}</p>
  
  <p>it doesn't work. This is the Contact ID token that CiviMail uses, and any other token I stick in there works (like contact.birth_date, which is what they are currently using). But the Contact ID token won't work. Any ideas?</p>
  
Tags: <tokens>
Title: Contact ID Token for Sort Name
ThreadText: # Contact ID Token for Sort Name
  
  (Asked by: username_0 on 2019-01-04)
  
  I have a client who wants to use the the contact id as an identifier in the Individual Sort Name Format. Basically they want to see "Smith, John (6548)" in search results because they want to use the ID to link to some paper files they are required to keep and they have a lot of contacts with identical names.
  
  At the bottom of Administer --> Customize Data and Screens --> Display Preferences, you can set the Individual Sort Name Format using tokens. However, when I insert
  
  {contact.last\_name}{, }{contact.first\_name}{ }{contact.contact\_id}
  
  it doesn't work. This is the Contact ID token that CiviMail uses, and any other token I stick in there works (like contact.birth\_date, which is what they are currently using). But the Contact ID token won't work. Any ideas?
  
  **Tags:** tokens
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-04. Score: 3 | Accepted answer
  
  There's a [place in the CiviCRM code](https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/Address.php#L159) where all the possible contact tokens are defined - and they say which fields they correspond to.
  
  The line in question is:
  `'contact.contact_id' => CRM_Utils_Array::value('id', $fields),`
  which means, "populate the contact\_id token from the `id` field passed to this function".
  
  That's no doubt correct in some instances - but in this instance, the data is stored in `contact_id`. I was able to get the contact\_id to work in `display_name` and `sort_name` by changing this line to:
  
  `'contact.contact_id' => CRM_Utils_Array::value('id', $fields, CRM_Utils_Array::value('contact_id', $fields)),`.
  
  This translates to, "populate the contact\_id token from `id` if it exists, but `contact_id` if not".
  
  Whether you want to shepherd this change into upstream CiviCRM or not is up to you!
  
  
  ---
  
  