I have a simple Drupal webform that is integrated with Civi and creates a tagged contact. I use the approach described by @petednz at https://civicrm.org/blog/petednz/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and to create a Drupal user and log them in when the form is submitted. In my case this then gives them access to a larger form where I want them to be able to save a draft and return later, hence the need for the user account.
Here's the rule that I'm using:
{ "rules_friends_tag_account_create" : {
"LABEL" : "Self Create User Account and login",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "CiviCRM", "CiviCRM User" ],
"REQUIRES" : [ "civicrm", "rules" ],
"ON" : { "civicrm_entity_tag_create" : [] },
"IF" : [
{ "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ] } },
{ "data_is" : {
"data" : [ "civicrm-entity-tag:entity-table" ],
"value" : "civicrm_contact"
}
},
{ "data_is" : { "data" : [ "civicrm-entity-tag:tag-id" ], "value" : "6" } }
],
"DO" : [
{ "civicrm_entity_action_create_user" : {
"USING" : {
"civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ],
"is_active" : "1",
"notify" : "1",
"signin" : "1",
"username_format" : "first last"
},
"PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
}
},
{ "user_unblock" : { "account" : [ "civicrm-user" ] } },
{ "user_add_role" : { "account" : [ "civicrm-user" ], "roles" : { "value" : { "7" : "7" } } } }
]
} }
This has been working reliably for some months, and seems rock solid when I test it.
However I'm seeing behaviour from users that suggests that it isn't working all the time: i.e. sometimes I see that they have submitted the first form two or three times in quick succession, suggesting that they are not reaching the second form, but getting an access denied message instead, which is what would happen if the user account wasn't created for them.
Also, in recent days, I've seen on two or three occasions now the following error message in the Drupal log:
Unable to get variable civicrm_user, it is not defined.
Why might this rule be working fine for much of the time, but not consistently? How can I debug this? Is there a more robust approach that I could take?