2

I am using the Profile 2 module to select roles during the registration process. So a user selects a role (using a radio button) and then a rule fires to give the user the role that was selected.

Here is the rule I'm using:

    { "rules_give_user_a_role_after_registration" : {
    "LABEL" : "Give user a role after registration",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_insert" : [] },
    "IF" : [
      { "data_is" : {
          "data" : [ "account:profile-main:field-user-role" ],
          "value" : "Emporos"
        }
      }
    ],
    "DO" : [
      { "user_add_role" : { "account" : [ "account" ], "roles" : { "value" : { "5" : "5" } } } }
    ]
  }
}

The issue is that the role is not assigned to the user. Any idea why not?

  • Next time, please post us the output of rules debug info (admin/config/workflow/rules/settings - 'Show debug information' - 'Always'). It is very helpful in such situations. – m1n0 Feb 23 '14 at 19:57
1

If "...the role is not assigned to the user..." (as in your question), it must be that your Rules Action is not performed. And if that's the case, then that must be because your Rules Condition is not satisfied (true).

And the reason why your Rules Condition is not true, is pretty sure because you should add another Rules Condition Entity has field (related to your additional field in the Rules Condition you already have). And make sure to add that Entity has field condition BEFORE the Rules Condition in which you want to perform that "data to compare".

That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')".

For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.

0

Anyway I found a solution without using Rules and Profile 2.Instead using the Auto assign role module https://drupal.org/project/autoassignrole It gives you the ability to select a role during registration.

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.