1

Using Drupal Workflow Rules with CiviCRM Entity to create a Drupal User after a new Civi contact is created.

Rule works fine if the only condition is that a new Drupal user can be created for the Civi contact.

I need to add an additional condition to limit the creation of the new Drupal user according to other criteria. Examples might be group membership or a Civi tag or certain Civi contact subtypes.

here is the rule that is not working:

{ "rules_testnewcontact" : { "LABEL" : "TestNewContact", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "civicrm", "rules" ], "ON" : { "civicrm_contact_create" : [] }, "IF" : [ { "civicrm_entity_user_exists_or_creatable" : { "civicrm_contact" : [ "civicrm_contact" ] } }, { "NOT text_matches" : { "text" : [ "civicrm-contact:contact-sub-type" ], "match" : "Client" } } ], "DO" : [ { "civicrm_entity_action_load_create_user" : { "USING" : { "civicrm_contact" : [ "civicrm_contact" ], "is_active" : "1", "notify" : "1" }, "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created or Loaded Drupal User" } } } } ] } }

1
+50

Well to answer this question, basically I had to write a couple of new Rules conditions. They have been added to the CiviCRM Entity project, right now they are in the -dev version.

I added two new Conditions. CiviCRM Contact is of subtype, and CiviCRM Contact is in Group.

They both require a civicrm_contact object is loaded in the rule, which you get automatically if you are reacting to "CiviCRM Contact is created", or "CiviCRM Contact is updated" Rules events.

The "CiviCRM Contact is of subtype" rule allows you to select which contact subtype to check for.

The "CiviCRM Contact is in Group" rule allows you to select which group to check if the contact is in.

This functionality will be in the next stable version of CiviCRM Entity.

These conditions are used as any other Rules conditions are....

Here's a sample of a Rule that shows a message on the site if a contact with sub-type Student is updated:

{ "rules_show_message_if_contact_is_subtype_student" : {
    "LABEL" : "Show Message if contact is subtype student",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "civicrm_entity", "rules", "civicrm" ],
    "ON" : { "civicrm_contact_edit" : [] },
    "IF" : [
      { "civicrm_entity_contact_is_subtype" : {
          "civicrm_contact" : [ "civicrm_contact" ],
          "contact_subtype" : "Student"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Contact of subtype student saved!" } }
    ]
  }
}

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.