2

I am trying to set up a rule to create a Drupal User when a Contact is created. The obvious approach is to fire on the event 'CiviCRM Contact has been created, check for the correct Contact subtype, and that a User does not already exist, and then use the action 'Create Linked Drupal User Account'.

This does not work on creating a Contact, giving an error message: Cannot create user, email: invalid!!

The Rules debug information in this case is:

0 ms Reacting on event CiviCRM Contact has been created. 2.397 ms Evaluating conditions of rule Test Rule. [edit] 2.473 ms The condition civicrm_entity_contact_is_subtype evaluated to TRUE [edit] 6.878 ms The condition civicrm_entity_user_exists evaluated to FALSE [edit] 6.88 ms AND evaluated to TRUE. Rule Test Rule fires [edit] 0 ms Rule Test Rule fires. 0.041 ms Evaluating the action civicrm_entity_action_create_user. [edit] 232.936 ms Rule Test Rule has fired. 239.83 ms Finished reacting on event CiviCRM Contact has been created.

The only messages in the Drupal log are copies of the error message and the Rules debug log.

BUT if one then updates the same Contact, using the same webform and the same Rule with the Contact Updated event added, it works and the User is created. (This says a timing or sequencing problem to me, or a difference I haven't spotted in the syntax required in the two cases.)

What is going on?

The Rule export is:

{ "rules_test_rule" : { "LABEL" : "Test Rule", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "civicrm_entity", "civicrm" ], "ON" : { "civicrm_contact_create" : [], "civicrm_contact_edit" : [] }, "IF" : [ { "civicrm_entity_contact_is_subtype" : { "civicrm_contact" : [ "civicrm_contact" ], "contact_subtype" : "xxxx_Member" } }, { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm_contact" ] } } ], "DO" : [ { "civicrm_entity_action_create_user" : { "USING" : { "civicrm_contact" : [ "civicrm-contact" ], "is_active" : "1", "notify" : "0", "signin" : "1", "username_format" : "firstlast" }, "PROVIDE" : { "civicrm_user" : { "username" : "Created Drupal User" } } } } ] } }

Configuration includes: CiviCRM 5.3.2 (including CiviCRM Rules Integration);
Drupal 7.59;
CiviCRM Entity 7.x-2.1;
Rules 7.x-2.11;
and dependencies.

(I have looked at the answers to various related questions and cannot get any joy. Those that are using the same approach don't seem be any help in getting mine working. Some suggest setting a Tag and then firing a rule off the Tag creation event - the CiviCRM Tag entity does not show up in the event selection list on my system, so I can't use that.

I have done something similar to the Tag suggestion using the Relationship created event, which does work (as far as I have tested it so far) but it's clearly a kludge (apologies) workaround. Should not the straightforward approach work?)

Thanks in advance, Tony

  • What!?! My 'use a tag' is a kludge? Oh that's right, it is. Be good for someone to work out the cleaner solution. Good luck if you take it on – petednz - fuzion Aug 19 '18 at 17:43
  • As stated, firing from the Relationship created event works, but in fact I have gone away from using Webforms for this purpose since they do not support Price Sets which I need to provide Membership options effectively. Also we decided that we got a better workflow if people registered as users, and were validated at that point, before taking out the Membership. – maynardsmith Oct 17 '18 at 14:01
  • maynard - this may not contradict your point, but i want to ensure you are aware of this civicrm.stackexchange.com/questions/26358/… – petednz - fuzion Oct 17 '18 at 18:26
1

This could be caused that in CiviCRM an e-mail address is its own entity and created after the contact has been created.

Meaning that at the point the trigger contact created is fired there is no e-mail address in the database (yet). That one is added afterwards.

CiviCRM has functionality which is called profiles and which also create a user account. So maybe you can use a profile to create the contact and its related user account.

  • See note above about firing off Relationship Creation. – maynardsmith Oct 17 '18 at 14:07

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.