Answers.Body: <p>First, make sure you have <a href="https://www.drupal.org/project/rules" rel="noreferrer">Drupal Rules</a> module and <a href="https://www.drupal.org/project/civicrm_entity" rel="noreferrer">CiviCRM Entity</a> module installed and enabled.</p>
  
  <p>Next, you must name your rule and select an event first and click save, then the condition and action options will be opened up to you.</p>
  
  <p>When you get to the action part, you will see options for how to assign the username (such as "use email address" or "first name.last name", etc. and you can chose if the contact is emailed or not. If you chose for the contact to be emailed, they will be emailed a one-time link to log in and set a password.</p>
  
  <p>Alternatively, you can import the rule instead, using this code: </p>
  
  <p>Go to <strong>Administration » Configuration » Workflow » Rules</strong> and click "<strong>+ Import Rule</strong>". Then, paste the following code in and click import:</p>
  
  <pre><code>{ "rules_create_drupal_account_from_civicrm_contact" : {
      "LABEL" : "Create Drupal Account from CiviCRM contact",
      "PLUGIN" : "reaction rule",
      "OWNER" : "rules",
      "REQUIRES" : [ "civicrm" ],
      "ON" : { "civicrm_contact_edit" : [], "civicrm_contact_create" : [] },
      "IF" : [
        { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm_contact" ] } }
      ],
      "DO" : [
        { "civicrm_entity_action_create_user" : {
            "USING" : {
              "civicrm_contact" : [ "civicrm_contact" ],
              "is_active" : "1",
              "notify" : "1",
              "signin" : "0",
              "username_format" : "email"
            },
            "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
          }
        }
      ]
    }
  }
  </code></pre>
  
  <p>Note: this code will do the following: Upon updating a contact record in the CiviCRM, it will check to see if the user has a Drupal account and if not, it will make one using the contacts email address. Then it will email them a one-time link to set their password. You can use this code and then edit the rule to tweak the activity.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-02T17:42:22.740Z
Answers.Text: Did my answer help you and if so, would you consider accepting it or let us know either way? Thank you.
Answers.UserDisplayName: Christia
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-04T09:28:14.513Z
Answers.LastActivityDate: 2017-01-04T10:29:06.567Z
Answers.LastEditDate: 2017-01-04T10:29:06.567Z
Answers.UserDisplayName: Christia
Answers.Body: <p>I realize the request was specifically about CiviCRM <em>contacts</em>, but I also wanted to share a similar Rule <em>specifically</em> for memberships <em>(to ensure a Drupal account is created)</em> for those searching.</p>
  
  <p>Here's the rule for folks looking for that:</p>
  
  <pre><code>{ "rules_civicrm_create_drupal_user_on_new_membership_" : {
    "LABEL" : "CiviCRM: Create Drupal User (on new membership)",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "CALACS" ],
    "REQUIRES" : [ "civicrm", "rules" ],
    "ON" : { "civicrm_membership_create" : [], "civicrm_membership_edit" : [] },
    "IF" : [
      { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ] } }
    ],
    "DO" : [
      { "entity_fetch" : {
        "USING" : { "type" : "civicrm_contact", "id" : [ "civicrm-membership:contact-id" ] },
        "PROVIDE" : { "entity_fetched" : { "contact_fetched" : "Contact for Membership" } }
          }
        },
        { "civicrm_entity_action_create_user" : {
          "USING" : {
              "civicrm_contact" : [ "contact-fetched" ],
              "is_active" : "1",
              "notify" : "1",
              "signin" : "0",
              "username_format" : "email"
            },
            "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
          }
        }
      ]
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-31T18:25:53.800Z
Answers.LastActivityDate: 2018-10-31T18:25:53.800Z
Answers.UserDisplayName: shaneonabike
Body: <p>I’m using civicrm 4.7.14 with drupal 7.53.</p>
  
  <p>I have a question about these directions:
  <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Creating+a+Drupal+user+for+every+CiviCRM+contact" rel="nofollow noreferrer">https://wiki.civicrm.org/confluence/display/CRMDOC/Creating+a+Drupal+user+for+every+CiviCRM+contact</a></p>
  
  <p>When I create the rule, I don't see these options listed as a condition or action:</p>
  
  <blockquote>
    <p>CONDITION</p>
    
    <p>NOT Drupal User Account exists for Contact</p>
    
    <p>ACTION</p>
    
    <p>Create Linked Drupal User Account</p>
  </blockquote>
  
  <p>What am I missing?</p>
  
  <p><a href="https://i.sstatic.net/MMNip.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MMNip.png" alt="screenshot showing available con"></a></p>
  
  <p>Also, what exactly happens here? I understand that new Drupal accounts will be made for the CiviCRM contacts, but will it generate usernames? Will it email everyone on the list automatically? (I don't want to send emails yet.)</p>
  
Tags: <drupal><user-account>
Title: Setting up rule to link CiviCRM contact with Drupal 7 account
ThreadText: # Setting up rule to link CiviCRM contact with Drupal 7 account
  
  (Asked by: username_0 on 2017-01-03)
  
  I’m using civicrm 4.7.14 with drupal 7.53.
  
  I have a question about these directions:
  <https://wiki.civicrm.org/confluence/display/CRMDOC/Creating+a+Drupal+user+for+every+CiviCRM+contact>
  
  When I create the rule, I don't see these options listed as a condition or action:
  
  > CONDITION
  >
  > NOT Drupal User Account exists for Contact
  >
  > ACTION
  >
  > Create Linked Drupal User Account
  
  What am I missing?
  
  [![screenshot showing available con](https://i.sstatic.net/MMNip.png)](https://i.sstatic.net/MMNip.png)
  
  Also, what exactly happens here? I understand that new Drupal accounts will be made for the CiviCRM contacts, but will it generate usernames? Will it email everyone on the list automatically? (I don't want to send emails yet.)
  
  **Tags:** drupal, user-account
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-01-04. Score: 5
  
  First, make sure you have Drupal Rules module and CiviCRM Entity module installed and enabled.
  Next, you must name your rule and select an event first and click save, then the condition and action options will be opened up to you.
  When you get to the action part, you will see options for how to assign the username (such as "use email address" or "first name.last name", etc. and you can chose if the contact is emailed or not. If you chose for the contact to be emailed, they will be emailed a one-time link to log in and set a password.
  Alternatively, you can import the rule instead, using this code: 
  Go to Administration » Configuration » Workflow » Rules and click "+ Import Rule". Then, paste the following code in and click import:
  { "rules_create_drupal_account_from_civicrm_contact" : {
      "LABEL" : "Create Drupal Account from CiviCRM contact",
      "PLUGIN" : "reaction rule",
      "OWNER" : "rules",
      "REQUIRES" : [ "civicrm" ],
      "ON" : { "civicrm_contact_edit" : [], "civicrm_contact_create" : [] },
      "IF" : [
        { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm_contact" ] } }
      ],
      "DO" : [
        { "civicrm_entity_action_create_user" : {
            "USING" : {
              "civicrm_contact" : [ "civicrm_contact" ],
              "is_active" : "1",
              "notify" : "1",
              "signin" : "0",
              "username_format" : "email"
            },
            "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
          }
        }
      ]
    }
  }
  
  Note: this code will do the following: Upon updating a contact record in the CiviCRM, it will check to see if the user has a Drupal account and if not, it will make one using the contacts email address. Then it will email them a one-time link to set their password. You can use this code and then edit the rule to tweak the activity.
  
  > **Comments:**
  > **username_1**: Did my answer help you and if so, would you consider accepting it or let us know either way? Thank you.  
  
  ---
  
  ### Answer by username_2 on 2018-10-31. Score: 2
  
  I realize the request was specifically about CiviCRM contacts, but I also wanted to share a similar Rule specifically for memberships (to ensure a Drupal account is created) for those searching.
  Here's the rule for folks looking for that:
  { "rules_civicrm_create_drupal_user_on_new_membership_" : {
    "LABEL" : "CiviCRM: Create Drupal User (on new membership)",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "CALACS" ],
    "REQUIRES" : [ "civicrm", "rules" ],
    "ON" : { "civicrm_membership_create" : [], "civicrm_membership_edit" : [] },
    "IF" : [
      { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ] } }
    ],
    "DO" : [
      { "entity_fetch" : {
        "USING" : { "type" : "civicrm_contact", "id" : [ "civicrm-membership:contact-id" ] },
        "PROVIDE" : { "entity_fetched" : { "contact_fetched" : "Contact for Membership" } }
          }
        },
        { "civicrm_entity_action_create_user" : {
          "USING" : {
              "civicrm_contact" : [ "contact-fetched" ],
              "is_active" : "1",
              "notify" : "1",
              "signin" : "0",
              "username_format" : "email"
            },
            "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
          }
        }
      ]
    }
  }
  
  
  ---
  
  