How to grab a user's Fivestar voting value with Rules? On my website, users can rate nodes via comments. The Fivestar field is called 'Stars'. I'd like to use the user's voting value in a rule that's activated when a new comment has been saved. (The rule should update a radioactivity field, called 'Popularity', from the node that's commented on.)

When debugging the 'Stars' field in a comment, I'm able to get exactly the value I need via field_stars['und'][0]['rating']. However, I can't find a way to grab it in the Rules UI. I'm always ending up with comment:field-stars: in an action.

I tried adding a condition 'Entity has field: Parameter: Entity: [comment:node], Field: field_stars'. This gave me the option to dig deeper to comment:field-stars:user-rating, but when I'm using it further on in my rule, it always throws an error "The variable or parameter value is empty."

What's going wrong and how can I solve this?



Edit: After reading this question, I tried solving my problem with the following rule.

{ "rules_new_vote" : {
    "LABEL" : "New vote",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "php", "radioactivity", "comment" ],
    "ON" : { "comment_insert--comment_node_article" : { "bundle" : "comment_node_article" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "comment:node" ], "field" : "field_popularity" } }
    ],
    "DO" : [
      { "variable_add" : {
          "USING" : { "type" : "integer", "value" : "0" },
          "PROVIDE" : { "variable_added" : { "null" : "null" } }
        }
      },
      { "php_eval" : { "code" : "$rating = \u0026drupal_static(\u0027rating\u0027, $default_value = $comment-\u003Efield_stars[\u0027und\u0027][0][\u0027rating\u0027]);" } },
      { "radioactivity_emit" : {
          "data" : [ "comment:node:field-popularity" ],
          "value" : { "select" : "null", "php" : { "code" : "return $rating;" } }
        }
      }
    ]
  }
}


Unfortunately, it doesn't work properly: when saving a comment, the following error is thrown:


  Notice: Undefined variable: rating in eval() (line 1 of
  C:\wamp\www\mysite\sites\all\modules\rules\modules\php.eval.inc(146)
  : eval()'d code).


How can I solve this?
I finally found a solution for my problem. This is my exported rule:

{ "rules_new_vote" : {
    "LABEL" : New vote",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "php", "radioactivity", "comment" ],
    "ON" : { "comment_insert--comment_node_article" : { "bundle" : "comment_node_article" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "comment:node" ], "field" : "field_popularity" } }
    ],
    "DO" : [
      { "variable_add" : {
          "USING" : {
            "type" : "integer",
            "value" : {
              "select" : "comment:cid",
              "php" : { "code" : "$comment = comment_load($value);\r\n$vote = $comment-\u003Efield_stars[\u0027und\u0027][0][\u0027rating\u0027\r\nif ($vote == 20) {return -4;}\ r\nif ($vote == 40) {return 2;}\r\nif ($vote == 60) {return 3;}\r\nif ($vote == 80) {return 4;}\r\nif ($vote == 100) {return 5;}" }
            }
          },
          "PROVIDE" : { "variable_added" : { "rating" : "Rating" } }
        }
      },
      { "radioactivity_emit" : { "data" : [ "comment:node:field-popularity" ], "value" : [ "rating" ] } }
    ]
  }
}


The trick was to store the cid as a new variable and to use that value in the PHP evaluation (the proposed values in my code can be changed to your needs). I've no idea why this wasn't possible in an easier way via the UI, but maybe it's a bug in the Firestar module.