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?

1 Answer 1


There's a place in the CiviCRM code 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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.