Why do both Text- and Data comparison seem to not work in my Rules conditions? I’m using Drupal 7.56, the Rules module 7.x-2.11, and CiviCRM 4.6.31.

I've been using the Text comparison and Data comparison conditions.

Using the Text comparison condition, the condition is always met, so the action is always executed, despite the value of the data.

Why does this condition always evaluate to TRUE, for all the possible values, even when the text of the data is different to the matching text?

This is the log entry.


  The condition text_matches evaluated to TRUE. 


This is the export of the rule.

{ "rules_create_a_drupal_account_for_a_civicrm_contact" : {
    "LABEL" : "Create a Drupal account for a CiviCRM contact",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "civicrm", "rules", "devel" ],
    "ON" : { "civicrm_membership_create" : [] },
    "IF" : [
      { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ] } },
      { "AND" : [
          { "NOT data_is_empty" : { "data" : [ "civicrm-membership:contact-id-contact:contact-sub-type" ] } },
          { "AND" : [
              { "text_matches" : {
                  "text" : [ "civicrm-membership:contact-id-contact:contact-sub-type" ],
                  "match" : "Parent"
                }
              }
            ]
          }
        ]
      }
    ],
    "DO" : [
      { "devel_debug" : { "value" : [ "civicrm-membership:contact-id-contact:contact-sub-type" ] } },
      { "civicrm_entity_action_create_user" : {
          "USING" : {
            "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ],
            "is_active" : "1",
            "notify" : "0",
            "signin" : "0",
            "username_format" : "email"
          },
          "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
        }
      },
      { "user_add_role" : { "account" : [ "civicrm-user" ], "roles" : { "value" : { "5" : "5" } } } }
    ]
  }
}


Using the Data comparison condition, the condition is never met and the action is never executed, despite the data to compare.

Why does this condition always evaluate to FALSE, for all the data, even when it is the same to the value to compare?

This is the log entry.


  The condition data_is evaluated to FALSE.


This is the export of the rule.

{ "rules_create_a_drupal_user_account2" : {
    "LABEL" : "Create a Drupal User Account2",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "civicrm", "rules" ],
    "ON" : { "civicrm_membership_create" : [] },
    "IF" : [
      { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ] } },
      { "AND" : [] },
      { "data_is" : {
          "data" : [ "civicrm-membership:contact-id-contact:contact-sub-type" ],
          "value" : "Parent"
        }
      }
    ],
    "DO" : [
      { "civicrm_entity_action_create_user" : {
          "USING" : {
            "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ],
            "is_active" : "1",
            "notify" : "0",
            "signin" : "0",
            "username_format" : "email"
          },
          "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
        }
      }
    ]
  }
}


Any clue about what might be happening?
I am not sure it is your only problem, but for sure you are not correctly using the AND constructs in your rule. It is one of the typical mistakes many Rules users make, but if you want to model a condition like A AND B, then first you must have a line with AND, and that should be followed with A and then also folowed by B. Something like so:

AND
  A
  B


For way more details, refer to my answer to Combining AND and OR in Rules.

So start with fixing this, and then verify if your issue is solved or not.

As a sample, just import this minor variation of your last rule (note I slightly renamed the rule to not overwrite your existing one, and moved the AND construct to where it belongs):

{ "rules_create_a_drupal_user_by_pierre" : {
    "LABEL" : "Create a Drupal User By Pierre",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "civicrm", "rules" ],
    "ON" : { "civicrm_membership_create" : [] },
    "IF" : [
      { "AND" : [] },
      { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ] } },
      { "data_is" : {
          "data" : [ "civicrm-membership:contact-id-contact:contact-sub-type" ],
          "value" : "Parent"
        }
      }
    ],
    "DO" : [
      { "civicrm_entity_action_create_user" : {
          "USING" : {
            "civicrm_contact" : [ "civicrm-membership:contact-id-contact" ],
            "is_active" : "1",
            "notify" : "0",
            "signin" : "0",
            "username_format" : "email"
          },
          "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
        }
      }
    ]
  }
}


If the above still doesn't solve your issue, then I suggest you do some extra Rules debugging as explained in my answer to "How can I display the value of a variable inside a condition?".

Update:

The above (related tot the AND-construct) is for sure "a" reason why it doesn't work. However, yet another issue you may have to correct, is related to what you wrote in a comment below this answer, i.e. this part of it:


  ... The value of the variable is the expected, but I'm not sure if I'm accessing in the right way to the variable, as it's an array: ... (Array, 1 element) 0 (String, 6 characters) Parent


If what you're trying to compare is an array (a "list of values"), then you should NOT (repeat: NOT) use something like 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 the Rules Condition  List contains item. 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.