1

This should be easy, but I can't figure out what is going wrong. I have created a field on the user account called "User profile type." It has two options: "General user" and "Grant Network user".

I am trying to create a rule (using the Rules module)to apply a role to these options if they are selected upon saving or updating of the user account form.

However, despite everything I have tried, I can't get the data comparison to evaluate as TRUE:

  • I am selecting site:current-user:field-user-profile-type:0 as the data to compare.
  • Then, in the conditions field, I am given the option in the direct input method to choose the item I want.
  • I am trying to choose "Grant Network user" and it evaluates to FALSE every time no matter what I try.
  • I have set it up with an OR statement, so that I also am selecting site:current-user:field-user-profile-type:1 as well. But, neither of these will evaluate to TRUE.

The weird thing is that when I test these data selection values in a rule to show a message on the site, they both display a message of "Grant Network user."

So, I don't understand why the data comparison is evaluating to FALSE.

Any ideas? It's probably something simple, but I can't seem to figure it out.

Note: I have tried selecting the field without the colon, but it doesn't seem to work either. It makes sense to try that, but part of my problem is also that I want to be able to select for more than one item. I'd prefer to use a "contains" operator, but it isn't available, so I'm trying to use the "...:0" and "...:1" options with an OR statement to allow for both options being selected. Am I understanding this wrong?

4
  • You shouldn't have to be choosing the "...:0" option. Can you select simply "site:current-user:field-user-profile-type"?
    – rrr45
    Commented Jun 5, 2015 at 15:19
  • Thanks for your response! I have tried selecting it without the colon, but it doesn't seem to work either. It makes sense to try that, but part of my problem is also that I want to be able to select for more than one item. I'd prefer to use a "contains" operator, but it isn't available, so I'm trying to use the "...:0" and "...:1" options with an OR statement to allow for both options being selected. Am I understanding this wrong? Commented Jun 8, 2015 at 18:48
  • Ok, two things. 1. You should be referring to the user whose account is being updated--not "current user." If an admin updates someone's account they way you have it, then the change will be enacted on the admin's account, not the updated user. 2. Is "user profile type" a checkbox or radio button field?
    – rrr45
    Commented Jun 9, 2015 at 20:12
  • @rrr45 : Are you familiar with "List contains item"? Check my answer for details on that ... Commented Feb 19, 2017 at 14:19

1 Answer 1

0

As per the "site:current-user:field-user-profile-type:X" part of your question (X=0 or 1), it seems that your "User profile type" field is a multi value field. Whereas you're trying to use a Data Comparison rules condition. Sorry to say, but for a multi value field, you should NOT use a "Data Comparison", because that's like trying to compare an array with a single value (which doesn't make sense).

To get your rule to work like you want it to work, you should use these Rules Conditions (in the specified order):

  • Entity has field, for your "User profile type" field, to make it available for subsequent Rules Conditions and/or Rules Actions.
  • List contains item, whereas:
    • the list is also about that same "User profile type" field (since your field allows multiple values, it is also considered as a list).
    • the item you want to check for (if it is contained in the list) is (e.g) "Grant Network user".

With those 2 Rules Conditions, your Rules Actions should be performed as you want it to work. For the sake of (basic) unit testing, just (temporary) add a Rules Action like "Display a Drupal Message" (as the very first Rules Action), with whatever message text (eg: "bingo, Pierre is right ...").

For an example Rule (in rules export format) in which you can see this at work, refer to the answer to "How to check for product taxonomy term in Rules actions (Ubercart)". In that case it's about a list of taxonomy terms, but the idea is the same.

PS: I'm assuming this question is about D7 ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.