Answers.Body: <p>I'm assuming you are also using the CiviCRM Entity module?</p>
  
  <p>For it to work on membership create, you need to load the contact entity from the membership->contact_id property. </p>
  
  <p>Use the "Fetch entity by id" action.</p>
  
  <p>Because of this, you may need the <a href="https://www.drupal.org/project/rules_conditional" rel="nofollow noreferrer">Rules Conditional module</a>, which let's you put conditionals in the "actions" portion of the Rule.</p>
  
  <p>There you can add an "If" conditional action, and the "CiviCRM Contact is of subtype" condition provided by CiviCRM Entity should work for you there.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-17T08:42:07.750Z
Answers.Text: Yes, I'm using CiviCRM Entity module.   this is the export of the rule:
Answers.UserDisplayName: Cristina P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-17T08:46:59.517Z
Answers.Text: "ON" : { "civicrm_membership_create" : [] },
      "DO" : [
        { "entity_fetch" : {
            "USING" : { "type" : "civicrm_contact", "id" : [ "civicrm-membership:contact-id" ] },
            "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
          }
        },
        {"CONDITIONAL":
              "IF" : { "civicrm_entity_contact_is_subtype":{
                  "civicrm_contact" : [ "entity-fetched:contact-id-contact"],
                  "contact_subtype" : "Parent"}
Answers.UserDisplayName: Cristina P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-17T08:49:30.477Z
Answers.Text: But, it doen't work either, as it raises the Warning: explode() expects parameter 2 to be string, array given in civicrm_entity_contact_is_subtype() (line 2875 of .\civicrm_entity\civicrm_entity.module)
Answers.UserDisplayName: Cristina P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-17T08:54:19.187Z
Answers.Text: As the contact subtype got from the CiviCRM Contact Entity fetched is an Array, not a String:                                                                     ... (Array, 1 element)
       0 (String, 6 characters ) Parent                                                                                                And the condition civicrm_entity_contact_is_subtype is evaluated to FALSE
Answers.UserDisplayName: Cristina P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-17T08:59:43.310Z
Answers.Text: When I provide the CiviCRM Contact on the CiviCRM Contact create Event, the contact subtype got from this entity is a String. And in that case the condition "CiviCRM Contact is of subtype" is evaluated to TRUE.                                                                                                                                                                                                                                How should I manage the Array contact_sub_type variable?
Answers.UserDisplayName: Cristina P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-15T17:17:29.100Z
Answers.LastActivityDate: 2018-10-15T17:17:29.100Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>I’m using <strong>Drupal 7.56</strong>, the Rules module 7.x-2.11 and <strong>CiviCRM 4.6.31</strong>.</p>
  
  <p>I'm trying to create a <strong>Drupal Rule</strong> that checks the <strong>subtype of contact</strong> to create a Linked Drupal User Account just for a specific subtype of CiviCRM contacts when they submit a Membership Signup form.</p>
  
  <p>I need to trigger that rule when a <strong><em>"CiviCRM Membership has been created"</em></strong>, as Drupal needs an email to create the user account. If I include the Event "<strong><em>CiviCRM contact has been created</em></strong>" instead of "<em>CiviCRM Membership has been created</em>" to trigger the rule evaluation, the email for the contact is not available yet on the database, as e-mail address is an independent entity in CiviCRM and created after the contact has been created, so the rule fails when trying to create the Drupal user account.</p>
  
  <p>The condition "<strong><em>CiviCRM Contact is of subtype</em></strong>" only works if I make the CiviCRM contact available from the "<strong><em>CiviCRM contact has been created</em></strong>" Event. So when I have the Event <strong><em>"CiviCRM Membership has been created"</em></strong>, required for my rule to work, the CiviCRM Contact accessible from this Entity/Event (CiviCRM Membership) doesn't work with the condition "CiviCRM Contact is of subtype", as the Contact Subtype is an Array:</p>
  
  <p>... (Array, 1 element) </p>
  
  <pre><code> 0 (String, 6 characters) Parent
  </code></pre>
  
  <p>Is there any way to make CiviCRM Contact Entity accessible from two different Events that trigger the rule evaluation, as <strong><em>"CiviCRM Membership has been created"</em></strong> and "<strong><em>CiviCRM contact has been created</em></strong>", so that the condition "<strong><em>CiviCRM Contact is of subtype</em></strong>" can have the appropriate CiviCRM contact parameter?</p>
  
  <p>Or if it's not possible, how can I access the <strong>Array variable</strong>? I know I have to use the Rules Condition <strong>List contains item</strong>, but I'm not able to make "Contact Subtype" Array variable available to evaluate the Condition.</p>
  
  <p>Any help will be very much appreciated.</p>
  
Tags: <civicrm-entity><drupal-rules>
Title: Rule to create a Linked Drupal user account for a specific CiviCRM Contact Subtype
ThreadText: # Rule to create a Linked Drupal user account for a specific CiviCRM Contact Subtype
  
  (Asked by: username_0 on 2018-10-15)
  
  I’m using **Drupal 7.56**, the Rules module 7.x-2.11 and **CiviCRM 4.6.31**.
  
  I'm trying to create a **Drupal Rule** that checks the **subtype of contact** to create a Linked Drupal User Account just for a specific subtype of CiviCRM contacts when they submit a Membership Signup form.
  
  I need to trigger that rule when a ***"CiviCRM Membership has been created"***, as Drupal needs an email to create the user account. If I include the Event "***CiviCRM contact has been created***" instead of "*CiviCRM Membership has been created*" to trigger the rule evaluation, the email for the contact is not available yet on the database, as e-mail address is an independent entity in CiviCRM and created after the contact has been created, so the rule fails when trying to create the Drupal user account.
  
  The condition "***CiviCRM Contact is of subtype***" only works if I make the CiviCRM contact available from the "***CiviCRM contact has been created***" Event. So when I have the Event ***"CiviCRM Membership has been created"***, required for my rule to work, the CiviCRM Contact accessible from this Entity/Event (CiviCRM Membership) doesn't work with the condition "CiviCRM Contact is of subtype", as the Contact Subtype is an Array:
  
  ... (Array, 1 element)
  
  ```
   0 (String, 6 characters) Parent
  
  ```
  
  Is there any way to make CiviCRM Contact Entity accessible from two different Events that trigger the rule evaluation, as ***"CiviCRM Membership has been created"*** and "***CiviCRM contact has been created***", so that the condition "***CiviCRM Contact is of subtype***" can have the appropriate CiviCRM contact parameter?
  
  Or if it's not possible, how can I access the **Array variable**? I know I have to use the Rules Condition **List contains item**, but I'm not able to make "Contact Subtype" Array variable available to evaluate the Condition.
  
  Any help will be very much appreciated.
  
  **Tags:** civicrm-entity, drupal-rules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-10-15. Score: 1
  
  I'm assuming you are also using the CiviCRM Entity module?
  
  For it to work on membership create, you need to load the contact entity from the membership->contact\_id property.
  
  Use the "Fetch entity by id" action.
  
  Because of this, you may need the [Rules Conditional module](https://www.drupal.org/project/rules_conditional), which let's you put conditionals in the "actions" portion of the Rule.
  
  There you can add an "If" conditional action, and the "CiviCRM Contact is of subtype" condition provided by CiviCRM Entity should work for you there.
  
  > **Comments:**
  > **username_0**: Yes, I'm using CiviCRM Entity module.   this is the export of the rule:  
  > **username_0**: "ON" : { "civicrm_membership_create" : [] },     "DO" : [       { "entity_fetch" : {           "USING" : { "type" : "civicrm_contact", "id" : [ "civicrm-membership:contact-id" ] },           "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }         }       },       {"CONDITIONAL":             "IF" : { "civicrm_entity_contact_is_subtype":{                 "civicrm_contact" : [ "entity-fetched:contact-id-contact"],                 "contact_subtype" : "Parent"}  
  > **username_0**: But, it doen't work either, as it raises the Warning: explode() expects parameter 2 to be string, array given in civicrm_entity_contact_is_subtype() (line 2875 of .\civicrm_entity\civicrm_entity.module)  
  > **username_0**: As the contact subtype got from the CiviCRM Contact Entity fetched is an Array, not a String:                                                                     ... (Array, 1 element)      0 (String, 6 characters ) Parent                                                                                                And the condition civicrm_entity_contact_is_subtype is evaluated to FALSE  
  > **username_0**: When I provide the CiviCRM Contact on the CiviCRM Contact create Event, the contact subtype got from this entity is a String. And in that case the condition "CiviCRM Contact is of subtype" is evaluated to TRUE.                                                                                                                                                                                                                                How should I manage the Array contact_sub_type variable?  
  
  ---
  
  