Answers.Body: <p>Well to answer this question, basically I had to write a couple of new Rules conditions.  They have been added to the <a href="https://www.drupal.org/project/civicrm_entity" rel="nofollow noreferrer">CiviCRM Entity</a> project, right now they are in the -dev version.</p>
  
  <p>I added two new Conditions. CiviCRM Contact is of subtype, and CiviCRM Contact is in Group.</p>
  
  <p>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.</p>
  
  <p>The "CiviCRM Contact is of subtype" rule allows you to select which contact subtype to check for.</p>
  
  <p>The "CiviCRM Contact is in Group" rule allows you to select which group to check if the contact is in.</p>
  
  <p>This functionality will be in the next stable version of CiviCRM Entity.</p>
  
  <p>These conditions are used as any other Rules conditions are....</p>
  
  <p>Here's a sample of a Rule that shows a message on the site if a contact with sub-type Student is updated:</p>
  
  <pre><code>{ "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!" } }
      ]
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-17T15:54:23.290Z
Answers.LastActivityDate: 2017-07-17T15:54:23.290Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>Using Drupal Workflow Rules with CiviCRM Entity to create a Drupal User after a new Civi contact is created.</p>
  
  <p>Rule works fine if the only condition is that a new Drupal user can be created for the Civi contact.</p>
  
  <p>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.</p>
  
  <p>here is the rule that is not working:</p>
  
  <p>{ "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" } }
          }
        }
      ]
    }
  }</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-08T00:41:46.067Z
Comments.Text: I can replicate this issue, something funky going on as concerns Contact sub type property with contact as Drupal entity type...
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-16T23:01:36.343Z
Comments.Text: Dave T - you saw this blog with example rules? https://civicrm.org/blog/petednz/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and
Comments.UserDisplayName: petednz - fuzion
Tags: <civicrm-entity><drupal-rules>
Title: How to create a Drupal rules condition that checks CiviCRM contact's Group or Tag or Subtype
ThreadText: # How to create a Drupal rules condition that checks CiviCRM contact's Group or Tag or Subtype
  
  (Asked by: username_0 on 2017-07-08)
  
  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" } }
  }
  }
  ]
  }
  }
  
  **Tags:** civicrm-entity, drupal-rules
  
  > **Comments:**
  > **username_1**: I can replicate this issue, something funky going on as concerns Contact sub type property with contact as Drupal entity type...  
  > **username_2**: username_0 - you saw this blog with example rules? https://civicrm.org/blog/username_2/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-07-17. Score: 1 | Accepted answer
  
  Well to answer this question, basically I had to write a couple of new Rules conditions. They have been added to the [CiviCRM Entity](https://www.drupal.org/project/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!" } }
      ]
    }
  }
  
  ```
  
  
  ---
  
  