Simple Rule Example Using CiviCRM Entity

The new Drupal module CiviCRM Entity exposes 11 CiviCRM objects as Drupal Entities and provides rules support for these entities.  In this article I will demonstrate how to create a simple rule which creates a synced drupal user for the contact when the contact gets a membership.

This how-to assumes you have the Rules modules and the CiviCRM Entity module installed.

Create the rule:

  • admin/config/workflow/rules/reaction/add
  • for name enter Create Synced User When Contact Gets Membership
  • For React on Event: Select 'CiviCRM Membership has been created'
  • Click Save
  • Under Actions select 'Create Linked Drupal User Account'
  • Click Continue
  • The default value for the CiviCRM contact Contact Data selector field should already be correct but ensure it is: civicrm-membership:contact-id-contact
  • Check Activate account and Send ccount notification email if you wish
  • Click save

You can extend the rule

If you would like to only create the user for a specific membership type.

  • Under Conditions click the Add Condition link
  • For the Select the condition to add field select Data Comparison
  • Under Data to Compare use the data selector find the membership type id field of the membership object. It should be this: civicrm-membership:membership-type-id
  • Click Continue
  • Under Operator select equals
  • Under Data Value enter the membership type id of the membership type you'd like to create linked drupal users for
  • click save

 

Tags: