Answers.Body: <p>The <code>user_save()</code> function can't take CiviCRM data.  CiviCRM injects a profile into the user creation page when you create a user through the UI.</p>
  
  <p>To handle your scenario, you'll want to:</p>
  
  <ul>
  <li>Call <code>user_save()</code>.  It will return a user object, including the UID.</li>
  <li>Call the CiviCRM <code>UFMatch.get</code> API to get the corresponding Civi contact ID.</li>
  <li>Call <code>Contact.create</code> on the contact ID to insert the first/last name.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-18T16:55:28.863Z
Answers.LastActivityDate: 2017-05-18T16:55:28.863Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>Would it not work to change the dedupe rule to just check for email?
  Do you have multiple contacts with the same email address and different names?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-31T14:36:06.593Z
Answers.Text: If I change the dedup rule only to look at email, then the issue is avoided. But there are many contacts in my CiviCRM database with shared emails (ie young children have the same email address as a parent).  I think the bigger issue is the CiviCRM core logic in "/civicrm_user.inc" assumes that that the only time first name and last name are used is from a screen, never from an API call.
Answers.UserDisplayName: Sarah Poger Gladstone
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-31T04:58:50.787Z
Answers.LastActivityDate: 2016-10-31T04:58:50.787Z
Answers.UserDisplayName: frTommy
Body: <p>I am calling the Drupal API "user_save" to create a brand new Drupal user. This does create a new Drupal user. But this user does not have the CiviCRM first name or last name fields set. How can I pass first name and last name to the Drupal API "user_save"?</p>
  
  <p>I investigated how CiviCRM handles passing the firstname and last name when someone registers online (which includes a profile that collects first name and last name). CiviCRM only has a mechanism to deal with this situation when someone is online, not using the API, per code in the CiviCRM core file /sites/all/modules/civicrm/drupal/civicrm_user.inc</p>
  
  <p>This issue causes problems with my CiviCRM dedup rule, which is set to check for first name, last name and email. Since for any Drupal user created via the API does not pass the first name or last name, a new CiviCRM contact is created as well. (In addition to the Drupal user)</p>
  
  <p>In my scenario I have a civicrm contact called "testfirst", "testlast", "test@test.com" in the backoffice. I create a Drupal user for this contact (using the API user_save). This contact does get associated with the new Drupal user. However, there is also a brand new contact with the email address "test@test.com" but no other data. This brand new contact is getting created because the unsupervised dedup rule is checking for all 3 fields (first name, last name, and email). </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-15T19:13:25.670Z
Comments.Text: Did you check if Drupal Rules would be an option?
Comments.UserDisplayName: petednz - fuzion
Tags: <drupal><duplicate-contacts>
Title: How can I pass CiviCRM first name and last name fields to Drupal API user_save
ThreadText: # How can I pass CiviCRM first name and last name fields to Drupal API user_save
  
  (Asked by: username_0 on 2016-10-31)
  
  I am calling the Drupal API "user\_save" to create a brand new Drupal user. This does create a new Drupal user. But this user does not have the CiviCRM first name or last name fields set. How can I pass first name and last name to the Drupal API "user\_save"?
  
  I investigated how CiviCRM handles passing the firstname and last name when someone registers online (which includes a profile that collects first name and last name). CiviCRM only has a mechanism to deal with this situation when someone is online, not using the API, per code in the CiviCRM core file /sites/all/modules/civicrm/drupal/civicrm\_user.inc
  
  This issue causes problems with my CiviCRM dedup rule, which is set to check for first name, last name and email. Since for any Drupal user created via the API does not pass the first name or last name, a new CiviCRM contact is created as well. (In addition to the Drupal user)
  
  In my scenario I have a civicrm contact called "testfirst", "testlast", "test@test.com" in the backoffice. I create a Drupal user for this contact (using the API user\_save). This contact does get associated with the new Drupal user. However, there is also a brand new contact with the email address "test@test.com" but no other data. This brand new contact is getting created because the unsupervised dedup rule is checking for all 3 fields (first name, last name, and email).
  
  **Tags:** drupal, duplicate-contacts
  
  > **Comments:**
  > **username_1**: Did you check if Drupal Rules would be an option?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-05-18. Score: 1
  
  The `user_save()` function can't take CiviCRM data. CiviCRM injects a profile into the user creation page when you create a user through the UI.
  
  To handle your scenario, you'll want to:
  
  * Call `user_save()`. It will return a user object, including the UID.
  * Call the CiviCRM `UFMatch.get` API to get the corresponding Civi contact ID.
  * Call `Contact.create` on the contact ID to insert the first/last name.
  
  
  ---
  
  ### Answer by username_3 on 2016-10-31. Score: 0
  
  Would it not work to change the dedupe rule to just check for email?
  Do you have multiple contacts with the same email address and different names?
  
  > **Comments:**
  > **username_0**: If I change the dedup rule only to look at email, then the issue is avoided. But there are many contacts in my CiviCRM database with shared emails (ie young children have the same email address as a parent).  I think the bigger issue is the CiviCRM core logic in "/civicrm_user.inc" assumes that that the only time first name and last name are used is from a screen, never from an API call.  
  
  ---
  
  