When I use the Action 'Fetch entity by property' and select fetch a user by role, when the action is fired I get this error:

Warning: array_values() expects parameter 1 to be array, null given in rules_action_entity_query() (line 56 of /sites/all/modules/contrib/rules/modules/entity.eval.inc).

Any thoughts what might be the issue?

Comments

qasimzee’s picture

Priority: Normal » Major

ping. exactly facing the same issue

chirhotec’s picture

+1. Same exact problem.

chirhotec’s picture

A temporary work around I've been able to do is to use Views and Views Rules, to create a list of users filtered by role, and then loop on that list within rules.

maximpodorov’s picture

Fetching users by role is impossible currently. This is Entity API limitation (inability to query user properties which are not stored in users table itself).

maximpodorov’s picture

bobfries’s picture

Issue summary: View changes

To work around this you need to use a component in the rule.... So fetch ALL the users (or in my case I fetched all users by status: Active), then loop them and run a component. Then in the component you can check the user role before doing whatever you need to do.

THE MAIN RULE:

{ "rules_kpi_generate_report_nodes" : {
    "LABEL" : "KPI Generate Report Nodes",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "cron" : [] },
    "DO" : [
      { "entity_query" : {
          "USING" : {
            "type" : "user",
            "property" : "status",
            "value" : "1",
            "limit" : "9999"
          },
          "PROVIDE" : { "entity_fetched" : { "user_entity_fetched" : "Fetched user entity" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "user-entity-fetched" ] },
          "ITEM" : { "user_list_item" : "User list item" },
          "DO" : [
            { "component_rules_kpi_check_roles_generate_report_nodes" : { "looped_user" : [ "user-list-item" ] } }
          ]
        }
      }
    ]
  }
}

THE COMPONENT:

{ "rules_kpi_check_roles_generate_report_nodes" : {
    "LABEL" : "KPI Check Roles \u0026 Generate Report Nodes",
    "PLUGIN" : "rule set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "looped_user" : { "label" : "Looped User", "type" : "user" } },
    "RULES" : [
      { "RULE" : {
          "PROVIDE" : { "entity_created" : { "kpi_service_report_created" : "Created kpi service report" } },
          "IF" : [
            { "user_has_role" : { "account" : [ "looped-user" ], "roles" : { "value" : { "8" : "8" } } } }
          ],
          "DO" : [
            { "entity_create" : {
                "USING" : {
                  "type" : "node",
                  "param_type" : "kpi_service_report",
                  "param_title" : "KPI Service Report - [looped-user:name] - [site:current-date:custom:M Y]",
                  "param_author" : "1"
                },
                "PROVIDE" : { "entity_created" : { "kpi_service_report_created" : "Created kpi service report" } }
              }
            },
            { "data_set" : {
                "data" : [ "kpi-service-report-created:field-subject" ],
                "value" : [ "looped-user" ]
              }
            }
          ],
          "LABEL" : "Check for Engineers \u0026 Generate Report Nodes"
        }
      }
    ]
  }
}
TR’s picture

Priority: Major » Normal
Status: Active » Postponed

As noted in #5, this is blocked by #2152807: Fetch users by roles