4

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.

  • Do you have CiviCRM Entity module installed? – jackrabbithanna Jul 8 '18 at 2:32
  • Yes, I have that module installed. – Cristina P. Jul 9 '18 at 9:01
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
  • 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 – Cristina P. Jul 12 '18 at 12:29
  • 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, drupal.org/project/rules_conditional – jackrabbithanna Jul 12 '18 at 20:02

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.