2

I've got this scheme: entity person, bundle person, entity health, bundle health. Bundle health has field energy.

Bundle person has an entity reference of type health.

In Rules data selector, I want to access to person:health:energy. Is that possible?

2 Answers 2

1

Only, you have to add a Condition (in 'Elements') to the rule of the class "Entity has field", and then a whole bunch of the referenced fields of the entity will appear and will be available.

0

The "entity_has_field" is indeed the "clue" to answer your question.

Here is a sample of such rule (in Rules export format), which will send an eMail to the userid selected via the field field_blog_reviewer (= a field I added to my "Blog" content type that is defined as an entity reference to a 'user'), and this whenever a new node of content type "Blog" is saved:

{ "rules_notify_reviewer_about_outstanding_approval" : {
    "LABEL" : "Notify reviewer about outstanding approval",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--blog" : { "bundle" : "blog" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_blog_reviewer" } }
    ],
    "DO" : [
      { "mail" : {
          "to" : "[node:field-blog-reviewer]",
          "subject" : "Blog Post waiting your approval",
          "message" : "[node:author] has submitted a new Blog post waiting your approval.\r\n\r\nYou can review it at: [node:edit-url].",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Should you be interested in using the above rule, just use the Rules UI to "import" it. However, before doing so, make sure to first add a field with machine name field_blog_reviewer to content type named blog (this content type gets added automatically if you enable the "Blog" module).

If you try to import it without doing this, the rules "import" will fail with some type of integrity check error (in plain English: the import is rejected if the entity doesn't exist, and/or it doesn't have a field with the exact machine name). As a workaround you may also edit the exported rule above before starting the import, to make it fit the machine names of the field and the content type you want to use it for.

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.