Answers.Body: <p>I remember this issue from some time in the past, probably been on stackexchange here before. In the end, we developed a new Rules condition, provided by the CiviCRM Entity module, "CiviCRM Contact is of subtype". </p>
  
  <p>It is in the "CiviCRM" section of the options list when you choose your condition. </p>
  
  <p>Give that a try, I believe it will solve your problem. It is expecting one parameter, a Contact object. It then allows you to choose which subtype to look for.</p>
  
  <p>It is possible you will have to load the contact first, and put your conditional down in the actions section of your rule. </p>
  
  <p>To load the contact, use the "Fetch entity by ID" action, and pass it </p>
  
  <pre><code>civicrm-relationship:contact-id-a-contact:id
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-12T12:29:52.400Z
Answers.Text: I'm not sure where I should put the action to load the contact first. This is how I set up the actions and conditions, but it is not working yet:
  **CONDITIONS**
  _Can Fetch CiviCRM entity by property_
  Parameter: CiviCRM Entity type: contact, Property: Internal Contact ID, Value: [civicrm-relationshi:contact-id-a-contact:id]
  
  _CiviCRM Contact is of subtype_
  Parameter: CiviCRM Contact: [civicrm-relationship:contact-id-a-contact, Contact Sub Type: Child]
  
  **ACTIONS**
  _Fetch entity by id_
  Parameter: Entity type: CiviCRM Contact, Identifier: [civicrm-relationship:contact-id-a-contact:id
Answers.UserDisplayName: Cristina P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-12T20:02:07.610Z
Answers.Text: perhaps first try the condition "CiviCRM Contact is of subtype" with parameter civicrm-relationship:contact-id-a-contact without fetching the entity...if id doesn't work, you can add conditionals inside the Actions area with the Rules Conditional module, https://www.drupal.org/project/rules_conditional
Answers.UserDisplayName: jackrabbithanna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T14:38:41.110Z
Answers.LastActivityDate: 2018-07-09T14:38:41.110Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>I’m using <strong>Drupal 7.56</strong> and <strong>CiviCRM 4.6.31</strong>.</p>
  
  <p>I’ve been using Rules in Drupal, as I need to copy the Household Name to the Last Name of a Particular Individual contact subtype (Child) whenever the relationship between the Household and this type of Individual (Child) has been established, but the Drupal Rule is not working.</p>
  
  <p>Rule "<strong>Copy Family Name to Individual Last Name</strong>”</p>
  
  <p>I've set up the following conditions reacting on the Event <strong>“CiviCRM Relationship has been created</strong>”:</p>
  
  <p><strong>Conditions</strong></p>
  
  <p><em>ELEMENTS</em>  </p>
  
  <p><strong><em>Data comparison</em></strong></p>
  
  <p>Parameter: Data to compare: [civicrm-relationship:relationship-type-id, Data value: 8]</p>
  
  <p>(Type ID of Relationship between the Household and the Individual of type '<em>Child</em>')    </p>
  
  <p><em>AND</em>   </p>
  
  <p><strong><em>Text comparison</em></strong></p>
  
  <p>Parameter: Text: [civicrm-relationship:contact-id-a-contact:contact-sub-type, 
  Matching text: Child]</p>
  
  <p><em>Action</em>: Set a data Value</p>
  
  <p><em>Selected Data</em>:</p>
  
  <pre><code> civicrm-relationship:contact-id-a-contact:last-name
  </code></pre>
  
  <p><em>Value</em></p>
  
  <pre><code> civicrm-relationship:contact-id-b-contact:household-name   
  </code></pre>
  
  <p>This is the output to <em>debug the values</em> of the fields for 2 contacts:</p>
  
  <p>civicrm-relationship:contact-id-a-contact:contact-sub-type:</p>
  
  <pre><code>   0 (String, 6 characters ) Parent
  </code></pre>
  
  <p>civicrm-relationship:relationship-type-id: </p>
  
  <pre><code>   8
  </code></pre>
  
  <p>civicrm-relationship:contact-id-a-contact:contact-sub-type:</p>
  
  <pre><code>   0 (String, 5 characters ) Child
  </code></pre>
  
  <p>civicrm-relationship:relationship-type-id: </p>
  
  <pre><code>   8
  </code></pre>
  
  <p>These is the <em>Devel log</em>:</p>
  
  <p>•   Reacting on event CiviCRM Relationship has been created.</p>
  
  <p>•   Evaluating conditions of rule "Copy Family Name to Individual Last Name". </p>
  
  <p>•   The condition data_is evaluated to TRUE</p>
  
  <p>•   The condition text_matches evaluated to TRUE </p>
  
  <p>•   AND evaluated to TRUE.</p>
  
  <p>•   AND evaluated to TRUE.</p>
  
  <p>•   Rule "Copy Family Name to Individual Last Name" fires. </p>
  
  <ul>
  <li>Rule Copy Family Name to Individual Last Name fires.</li>
  <li>Evaluating the action data_set.</li>
  <li>Evaluating the action devel_debug.</li>
  <li>Evaluating the action devel_debug.</li>
  <li>Rule Copy Family Name to Individual Last Name has fired.</li>
  </ul>
  
  <p>•   Saved civicrm_relationship:contact_id_a_contact of typecivicrm_contact.</p>
  
  <p>•   Finished reacting on event CiviCRM Relationship has been created.</p>
  
  <p>But, despite the subtype of contact the action, the action is executed; even for the “<em>Parent</em>” contact subtype, when in the conditions is set up just for “<strong><em>Child</em></strong>”.</p>
  
  <p>Why the condition civicrm-relationship:contact-id-a-contact:contact-sub-type contains ‘<strong><em>Child</em></strong>’ is evaluated TRUE, for all the subtypes of contacts, even for the ‘<strong><em>Parent</em></strong>’ contact subtype?</p>
  
  <p>If I change the type of conditions to “<em>Data comparison</em>”:</p>
  
  <p><strong>Conditions</strong></p>
  
  <p>ELEMENTS    </p>
  
  <p><strong><em>Data comparison</em></strong></p>
  
  <p>Parameter: </p>
  
  <p>Data to compare: [civicrm-relationship:relationship -type-id, Data value: 8]</p>
  
  <p><em>AND</em></p>
  
  <p><strong><em>Data comparison</em></strong></p>
  
  <p>Parameter: </p>
  
  <p>Data to compare: 
  [civicrm-relationship:contact-id-a-contact:contact-sub-type, </p>
  
  <pre><code>               Operator: is one of, Data value: Child, ☺Child☺] 
  </code></pre>
  
  <p>These is the <em>Devel log</em>:</p>
  
  <p>•   Reacting on event CiviCRM Relationship has been created.</p>
  
  <p>•   Evaluating conditions of rule "Copy Family Name to Individual Last Name".</p>
  
  <p>•   The condition data_is evaluated to TRUE </p>
  
  <p>•   The condition data_is evaluated to FALSE </p>
  
  <p>•   AND evaluated to FALSE.</p>
  
  <p>•   AND evaluated to FALSE.</p>
  
  <p>•   Finished reacting on event CiviCRM Relationship has been created.</p>
  
  <p>The conditions are never met.</p>
  
  <p>Why the condition civicrm-relationship:contact-id-a-contact:contact-sub-type is one of ‘<em>Child</em>’ or ‘<em>☺Child☺</em>’ is evaluated FALSE for the contact subtype “<strong><em>Child</em></strong>”?</p>
  
  <p>Could someone have any tip about what is happening?</p>
  
  <p>Thank you so much for your help.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-08T02:32:42.257Z
Comments.Text: Do you have CiviCRM Entity module installed?
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-09T09:01:56.620Z
Comments.Text: Yes, I have that module installed.
Comments.UserDisplayName: Cristina P.
Tags: <drupal-rules>
Title: Drupal Rules are not working properly when check CiviCRM Contact's Subtype
ThreadText: # Drupal Rules are not working properly when check CiviCRM Contact's Subtype
  
  (Asked by: username_0 on 2018-06-25)
  
  I’m using **Drupal 7.56** and **CiviCRM 4.6.31**.
  
  I’ve been using Rules in Drupal, as I need to copy the Household Name to the Last Name of a Particular Individual contact subtype (Child) whenever the relationship between the Household and this type of Individual (Child) has been established, but the Drupal Rule is not working.
  
  Rule "**Copy Family Name to Individual Last Name**”
  
  I've set up the following conditions reacting on the Event **“CiviCRM Relationship has been created**”:
  
  **Conditions**
  
  *ELEMENTS*
  
  ***Data comparison***
  
  Parameter: Data to compare: [civicrm-relationship:relationship-type-id, Data value: 8]
  
  (Type ID of Relationship between the Household and the Individual of type '*Child*')
  
  *AND*
  
  ***Text comparison***
  
  Parameter: Text: [civicrm-relationship:contact-id-a-contact:contact-sub-type,
  Matching text: Child]
  
  *Action*: Set a data Value
  
  *Selected Data*:
  
  ```
   civicrm-relationship:contact-id-a-contact:last-name
  
  ```
  
  *Value*
  
  ```
   civicrm-relationship:contact-id-b-contact:household-name   
  
  ```
  
  This is the output to *debug the values* of the fields for 2 contacts:
  
  civicrm-relationship:contact-id-a-contact:contact-sub-type:
  
  ```
     0 (String, 6 characters ) Parent
  
  ```
  
  civicrm-relationship:relationship-type-id:
  
  ```
     8
  
  ```
  
  civicrm-relationship:contact-id-a-contact:contact-sub-type:
  
  ```
     0 (String, 5 characters ) Child
  
  ```
  
  civicrm-relationship:relationship-type-id:
  
  ```
     8
  
  ```
  
  These is the *Devel log*:
  
  • Reacting on event CiviCRM Relationship has been created.
  
  • Evaluating conditions of rule "Copy Family Name to Individual Last Name".
  
  • The condition data\_is evaluated to TRUE
  
  • The condition text\_matches evaluated to TRUE
  
  • AND evaluated to TRUE.
  
  • AND evaluated to TRUE.
  
  • Rule "Copy Family Name to Individual Last Name" fires.
  
  * Rule Copy Family Name to Individual Last Name fires.
  * Evaluating the action data\_set.
  * Evaluating the action devel\_debug.
  * Evaluating the action devel\_debug.
  * Rule Copy Family Name to Individual Last Name has fired.
  
  • Saved civicrm\_relationship:contact\_id\_a\_contact of typecivicrm\_contact.
  
  • Finished reacting on event CiviCRM Relationship has been created.
  
  But, despite the subtype of contact the action, the action is executed; even for the “*Parent*” contact subtype, when in the conditions is set up just for “***Child***”.
  
  Why the condition civicrm-relationship:contact-id-a-contact:contact-sub-type contains ‘***Child***’ is evaluated TRUE, for all the subtypes of contacts, even for the ‘***Parent***’ contact subtype?
  
  If I change the type of conditions to “*Data comparison*”:
  
  **Conditions**
  
  ELEMENTS
  
  ***Data comparison***
  
  Parameter:
  
  Data to compare: [civicrm-relationship:relationship -type-id, Data value: 8]
  
  *AND*
  
  ***Data comparison***
  
  Parameter:
  
  Data to compare:
  [civicrm-relationship:contact-id-a-contact:contact-sub-type,
  
  ```
                 Operator: is one of, Data value: Child, ☺Child☺] 
  
  ```
  
  These is the *Devel log*:
  
  • Reacting on event CiviCRM Relationship has been created.
  
  • Evaluating conditions of rule "Copy Family Name to Individual Last Name".
  
  • The condition data\_is evaluated to TRUE
  
  • The condition data\_is evaluated to FALSE
  
  • AND evaluated to FALSE.
  
  • AND evaluated to FALSE.
  
  • Finished reacting on event CiviCRM Relationship has been created.
  
  The conditions are never met.
  
  Why the condition civicrm-relationship:contact-id-a-contact:contact-sub-type is one of ‘*Child*’ or ‘*☺Child☺*’ is evaluated FALSE for the contact subtype “***Child***”?
  
  Could someone have any tip about what is happening?
  
  Thank you so much for your help.
  
  **Tags:** drupal-rules
  
  > **Comments:**
  > **username_1**: Do you have CiviCRM Entity module installed?  
  > **username_0**: Yes, I have that module installed.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-09. Score: 1
  
  I remember this issue from some time in the past, probably been on stackexchange here before. In the end, we developed a new Rules condition, provided by the CiviCRM Entity module, "CiviCRM Contact is of subtype".
  
  It is in the "CiviCRM" section of the options list when you choose your condition.
  
  Give that a try, I believe it will solve your problem. It is expecting one parameter, a Contact object. It then allows you to choose which subtype to look for.
  
  It is possible you will have to load the contact first, and put your conditional down in the actions section of your rule.
  
  To load the contact, use the "Fetch entity by ID" action, and pass it
  
  ```
  civicrm-relationship:contact-id-a-contact:id
  
  ```
  
  > **Comments:**
  > **username_0**: I'm not sure where I should put the action to load the contact first. This is how I set up the actions and conditions, but it is not working yet: **CONDITIONS** _Can Fetch CiviCRM entity by property_ Parameter: CiviCRM Entity type: contact, Property: Internal Contact ID, Value: [civicrm-relationshi:contact-id-a-contact:id]  _CiviCRM Contact is of subtype_ Parameter: CiviCRM Contact: [civicrm-relationship:contact-id-a-contact, Contact Sub Type: Child]  **ACTIONS** _Fetch entity by id_ Parameter: Entity type: CiviCRM Contact, Identifier: [civicrm-relationship:contact-id-a-contact:id  
  > **username_1**: perhaps first try the condition "CiviCRM Contact is of subtype" with parameter civicrm-relationship:contact-id-a-contact without fetching the entity...if id doesn't work, you can add conditionals inside the Actions area with the Rules Conditional module, https://www.drupal.org/project/rules_conditional  
  
  ---
  
  