6

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

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.)

6

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.

  • Did my answer help you and if so, would you consider accepting it or let us know either way? Thank you. – Christia Oct 2 '18 at 17:42
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" } }
        }
      }
    ]
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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