Answers.Body: <p>As mentionned <a href="http://forum.civicrm.org/index.php/topic,23125.msg97204.html#msg97204" rel="nofollow">here</a> :</p>
  
  <ul>
  <li>You can export the first name, last name and the internal ID</li>
  <li>Re-import the data by matching the internal ID</li>
  </ul>
  
  <p>This process should regenerate the sort name and display name based on the current settings.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-09T12:41:53.780Z
Answers.Text: Used this. It works.
Answers.UserDisplayName: jursulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-30T06:59:17.083Z
Answers.LastActivityDate: 2015-04-30T06:59:17.083Z
Answers.UserDisplayName: samuelsov
Answers.Body: <p>If you have any familiarity with sql, the update statement is straight forward.  Of course, test first in a test environment.</p>
  
  <p>Here is one that would work for individuals with sort name like Smith, John and display name like John Smith.  </p>
  
  <pre><code>update civicrm_contact
  set    display_name = concat(first_name, " ", last_name),
         sort_name = concat(last_name, ", ", first_name)
  where  contact_type = 'Individual'
  </code></pre>
  
  <p>If you have a lot of contacts and don't want to update them all at once you could add</p>
  
  <pre><code>and id between 1 and 5000 -- or whatever and increment the numbers manually
  </code></pre>
  
  <p>You'd also might need a statement for organizations and households, but since there is really only one field to work with for them, I'm not sure any change in sort order or display would change these.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-10T13:32:43.983Z
Answers.Text: you saved my day
Answers.UserDisplayName: Guillaume Sorel
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-30T00:13:39.903Z
Answers.Text: Note that this won't work in general where display names (and maybe sort names also) are configurable by the admin via tokens. The display name also includes the prefix, suffix by default
Answers.UserDisplayName: Donald Lobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-30T06:45:14.613Z
Answers.Text: Also note that for some Europeans you have to also add the middle_name!
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T17:14:29.747Z
Answers.LastActivityDate: 2015-04-29T17:14:29.747Z
Answers.UserDisplayName: Paul-Tahoe
Answers.Body: <p>I dont think there is one right now, but the way to do it would probably be:</p>
  
  <p>a. Create a a job for this in api/v3/Job.php</p>
  
  <p>b. Do it similar to the address geocoding job. This is primarily because you could have lots of contacts and hence having an offset and a limit will be useful for some orgs. The job could potentially take a long time</p>
  
  <p>c. There probably are functions in the Contact BAO to generate the sort/display name that you can reuse (some refactoring of the code is probably needed here)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T14:16:56.650Z
Answers.LastActivityDate: 2015-04-29T14:16:56.650Z
Answers.UserDisplayName: Donald Lobo
Answers.Body: <p>I came across this issue today.  I needed to update the display name after an import (there were reasons for not using the API to create in this instance).</p>
  
  <p>I am using v5.6.1 (latest at the time of writing) and unfortunately the Export and Re-Import did not work for me as I could not choose to match on Contact_ID.  It may well be that the import function has changed since the original question, or I just could not find it...</p>
  
  <p>I ended up using the v4 API instead - if you have a collection of records you want to update, use the Contact::Update call.  I wanted to update all of my records, so I just used the GUI to specify Contacts of Type 'Individual' where the contact ID was great than 2 (after the admin).  </p>
  
  <p><a href="https://i.sstatic.net/CYhmK.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CYhmK.jpg" alt="enter image description here"></a></p>
  
  <p>The only issue I had was a timeout somewhere and so I did them in 10,000 batches. I could have done this in PHP but it was a simple fix without coding.</p>
  
  <p><strong>PLEASE NOTE WELL</strong> This works well for basic records - if you have contact subtypes and attached custom data, you may find that these are removed during a basic update</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-07T18:02:13.370Z
Answers.Text: I can absolutely still see Contact ID as an import field option on dmaster.demo.civicrm.org
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T10:35:46.350Z
Answers.Text: Many thanks for checking - I went to dmaster and tried again but still couldn't see it... So following your comment I absolutely knew it had to be there, I tried other options and have got to the bottom of the mystery of not being able to see the Contact_ID  - I had the default of 'Skip', but you need to have 'Update' or  'No duplicate checking'.... Now works perfectly!
Answers.UserDisplayName: ChumKui
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-10T15:35:55.063Z
Answers.Text: Recent CiviCRM versions (ex: 5.44) require at least one value, but if you filter contact_type = Individual, you can then set contact_type = Individual as the value, since at least one value is required.
Answers.UserDisplayName: bgm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-07T16:16:30.073Z
Answers.LastActivityDate: 2018-11-07T17:07:54.177Z
Answers.LastEditDate: 2018-11-07T17:07:54.177Z
Answers.UserDisplayName: ChumKui
Answers.Body: <p>We now use the following SQL to accomplish the outcome. Still I think it would be better to include this in the Update Greeting scheduled task </p>
  
  <pre><code># SET DISPLAYNAME (first,middle,last)
  UPDATE civicrm_contact
  SET    display_name = LTRIM(RTRIM(CONCAT(first_name, " ", middle_name, " ", last_name))),
         sort_name = LTRIM(RTRIM(CONCAT(last_name, ", ", first_name, " ", middle_name)))
  WHERE  contact_type = 'Individual'
  AND    first_name IS NOT NULL AND middle_name IS NOT NULL AND last_name IS NOT NULL;
  
  # SET DISPLAYNAME (first,last)  
  UPDATE civicrm_contact
  SET    display_name = LTRIM(RTRIM(CONCAT(first_name, " ", last_name))),
         sort_name = LTRIM(RTRIM(CONCAT(last_name, ", ", first_name)))
  WHERE  contact_type = 'Individual'
  AND    first_name IS NOT NULL AND middle_name IS NULL AND last_name IS NOT NULL;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-22T12:50:43.257Z
Answers.LastActivityDate: 2018-01-22T12:50:43.257Z
Answers.UserDisplayName: Richard van Oosterhout
Body: <p>After changing the display settings (/civicrm/admin/setting/preferences/display) for sort_name or display_name, is there a way to regenerate the sort_names and display_names currently in the database to the newly configured format?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-12T12:40:36.790Z
Comments.Text: I created an issue as a placeholder for creating a job to regenerate the display and sortnames https://issues.civicrm.org/jira/browse/CRM-16491
Comments.UserDisplayName: Richard van Oosterhout
Tags: <civicrm-home>
Title: Is there a way to regenerate the display and sort names?
ThreadText: # Is there a way to regenerate the display and sort names?
  
  (Asked by: username_0 on 2015-04-29)
  
  After changing the display settings (/civicrm/admin/setting/preferences/display) for sort\_name or display\_name, is there a way to regenerate the sort\_names and display\_names currently in the database to the newly configured format?
  
  **Tags:** civicrm-home
  
  > **Comments:**
  > **username_0**: I created an issue as a placeholder for creating a job to regenerate the display and sortnames https://issues.civicrm.org/jira/browse/CRM-16491  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_1 on 2015-04-30. Score: 4
  
  As mentionned [here](http://forum.civicrm.org/index.php/topic,23125.msg97204.html#msg97204) :
  
  * You can export the first name, last name and the internal ID
  * Re-import the data by matching the internal ID
  
  This process should regenerate the sort name and display name based on the current settings.
  
  > **Comments:**
  > **username_2**: Used this. It works.  
  
  ---
  
  ### Answer by username_3 on 2015-04-29. Score: 2
  
  If you have any familiarity with sql, the update statement is straight forward.  Of course, test first in a test environment.
  Here is one that would work for individuals with sort name like Smith, John and display name like John Smith.  
  update civicrm_contact
  set    display_name = concat(first_name, " ", last_name),
         sort_name = concat(last_name, ", ", first_name)
  where  contact_type = 'Individual'
  
  If you have a lot of contacts and don't want to update them all at once you could add
  and id between 1 and 5000 -- or whatever and increment the numbers manually
  
  You'd also might need a statement for organizations and households, but since there is really only one field to work with for them, I'm not sure any change in sort order or display would change these.
  
  > **Comments:**
  > **username_5**: Note that this won't work in general where display names (and maybe sort names also) are configurable by the admin via tokens. The display name also includes the prefix, suffix by default  
  > **username_6**: Also note that for some Europeans you have to also add the middle_name!  
  > **username_4**: you saved my day  
  
  ---
  
  ### Answer by username_5 on 2015-04-29. Score: 2
  
  I dont think there is one right now, but the way to do it would probably be:
  
  a. Create a a job for this in api/v3/Job.php
  
  b. Do it similar to the address geocoding job. This is primarily because you could have lots of contacts and hence having an offset and a limit will be useful for some orgs. The job could potentially take a long time
  
  c. There probably are functions in the Contact BAO to generate the sort/display name that you can reuse (some refactoring of the code is probably needed here)
  
  
  ---
  
  ### Answer by username_7 on 2018-11-07. Score: 2
  
  I came across this issue today. I needed to update the display name after an import (there were reasons for not using the API to create in this instance).
  
  I am using v5.6.1 (latest at the time of writing) and unfortunately the Export and Re-Import did not work for me as I could not choose to match on Contact\_ID. It may well be that the import function has changed since the original question, or I just could not find it...
  
  I ended up using the v4 API instead - if you have a collection of records you want to update, use the Contact::Update call. I wanted to update all of my records, so I just used the GUI to specify Contacts of Type 'Individual' where the contact ID was great than 2 (after the admin).
  
  [![enter image description here](https://i.sstatic.net/CYhmK.jpg)](https://i.sstatic.net/CYhmK.jpg)
  
  The only issue I had was a timeout somewhere and so I did them in 10,000 batches. I could have done this in PHP but it was a simple fix without coding.
  
  **PLEASE NOTE WELL** This works well for basic records - if you have contact subtypes and attached custom data, you may find that these are removed during a basic update
  
  > **Comments:**
  > **username_8**: I can absolutely still see Contact ID as an import field option on dmaster.demo.civicrm.org  
  > **username_7**: Many thanks for checking - I went to dmaster and tried again but still couldn't see it... So following your comment I absolutely knew it had to be there, I tried other options and have got to the bottom of the mystery of not being able to see the Contact_ID  - I had the default of 'Skip', but you need to have 'Update' or  'No duplicate checking'.... Now works perfectly!  
  > **username_9**: Recent CiviCRM versions (ex: 5.44) require at least one value, but if you filter contact_type = Individual, you can then set contact_type = Individual as the value, since at least one value is required.  
  
  ---
  
  ### Answer by username_0 on 2018-01-22. Score: 1
  
  We now use the following SQL to accomplish the outcome. Still I think it would be better to include this in the Update Greeting scheduled task 
  # SET DISPLAYNAME (first,middle,last)
  UPDATE civicrm_contact
  SET    display_name = LTRIM(RTRIM(CONCAT(first_name, " ", middle_name, " ", last_name))),
         sort_name = LTRIM(RTRIM(CONCAT(last_name, ", ", first_name, " ", middle_name)))
  WHERE  contact_type = 'Individual'
  AND    first_name IS NOT NULL AND middle_name IS NOT NULL AND last_name IS NOT NULL;
  
  # SET DISPLAYNAME (first,last)  
  UPDATE civicrm_contact
  SET    display_name = LTRIM(RTRIM(CONCAT(first_name, " ", last_name))),
         sort_name = LTRIM(RTRIM(CONCAT(last_name, ", ", first_name)))
  WHERE  contact_type = 'Individual'
  AND    first_name IS NOT NULL AND middle_name IS NULL AND last_name IS NOT NULL;
  
  
  ---
  
  