0

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.

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, 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.

  • Yes, I'm using CiviCRM Entity module. this is the export of the rule: – Cristina P. Oct 17 '18 at 8:42
  • "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"} – Cristina P. Oct 17 '18 at 8:46
  • 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) – Cristina P. Oct 17 '18 at 8:49
  • 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 – Cristina P. Oct 17 '18 at 8:54
  • 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? – Cristina P. Oct 17 '18 at 8:59

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.