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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • sort_name not getting set for some contacts, how to batch update?
Pages: [1]

Author Topic: sort_name not getting set for some contacts, how to batch update?  (Read 1001 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
sort_name not getting set for some contacts, how to batch update?
October 07, 2010, 08:48:58 am
Hi,

For some contacts with first and last name set, the sort_name is not getting set, sort_name remains their email.  Editing the contact via Contact Record and saving seems to fix this, and then the sort_name is set after the save.

My theory is these were Contacts that were created via Profile by users during Drupal registration, but I don't have any proof of that at the moment.

Is there a script to run to update sort_name for all contacts?  Would it be /bin/UpdateAddress.php or /bin/UpdateGreeting.php perhaps?
Try CiviTeacher: the online video tutorial CiviCRM learning library.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: sort_name not getting set for some contacts, how to batch update?
October 07, 2010, 09:02:04 am
I'd go sql (100% not tested, but should either put you in the right direction or explode your db):

Code: [Select]
UPDATE civicrm_contact set sort_name = CONCAT_WS (' ,', last_name, first_name) where sort_name like '%@%' and last_name is not null;

Assuming it hasn't screwed up your db (DO BACKUP FIRST), you might want to check the display_name and fix accordingly.

X+

P.S. Do backup first, I mean it.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: sort_name not getting set for some contacts, how to batch update?
October 07, 2010, 12:03:34 pm
Thx, I ran a backup don't worry.  ;)

The script worked, although I tweaked it a little.  I also ran a SELECT statement first to get an idea of how many records would be affected by the UPDATE, and the answer was 20.  Then I did the UPDATE.

I'm going to run that SELECT again in a couple of weeks to keep an eye on the count to determine if this is an ongoing problem for the database.

Try CiviTeacher: the online video tutorial CiviCRM learning library.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: sort_name not getting set for some contacts, how to batch update?
October 07, 2010, 11:38:05 pm
would the tweak be worth sharing? I just spotted this problem on one of our client's site - haven't dug to see where they are coming from but Drupal synch is one suspicion
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

pkeogan

  • I post frequently
  • ***
  • Posts: 130
  • Karma: 4
    • BackOffice Thinking
Re: sort_name not getting set for some contacts, how to batch update?
November 04, 2010, 01:14:05 pm
We are having the same issue with a few clients.  The sort name name is sometimes replaced by their email -- this happened to 238 of 25,000 individual contacts.  The same type of issue with display name, but they tend to be missing middle name, Prefix, Suffix.

These are fixed one at a time by the editing the record or I can update the database record.

Is this something relatively new (version 3.2x)? 

Any idea what may be causing it?  Does it have anything to do with updating the contact via a profile?

pkeogan

  • I post frequently
  • ***
  • Posts: 130
  • Karma: 4
    • BackOffice Thinking
Re: sort_name not getting set for some contacts, how to batch update?
November 04, 2010, 01:16:12 pm
BTW:  Have you noticed that the problem has returned once you updated the display and sort names?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • sort_name not getting set for some contacts, how to batch update?

This forum was archived on 2017-11-26.