0

I have a content type "Business" which has a field "Business Email".

I have an entity form with an Entity Reference field that allows a user to select mutliple businesses, leave a message and click send.

I need to send an email to the "Business Email" field of all referenced Businsess in the submission.

I have set up a Rule to react "After saving a new entityform submission" which checks "Enity has field:Business Email", and then sets up a send mail, but I am having trouble actually getting the value for business email and looping through it. Has anyone achieved something like that that can lend a hand?

1

Your rule should first use condition "Entity has field" on your entity reference field from the form -> the field where user selects businesses. In this case your form submission is the primary entity that your rule will target.

And then you'll have to loop through selected businesses and extract business email from each business that was selected by user in that form submission.

You can use components for getting email field out of your business entity or you can install "Conditional Rules" module (CR), which will allow you to write all the logic in rule's "actions" section without using components.

So your rule (if you installed CR) would be as follows:

Events: After saving a new entityform submission

Conditions: 1) Entity has field [entityform:field-select-business]

Actions: Your actions will look something like this. enter image description here Loop: here you loop through your Entity Reference field - [entityform:field-select-business]. You cannot loop through your Email field directly - every email is taken from refernced entity.

IF - here you will select conditional "Entity has field" Entity: [list-item], Field: [field_business_email] <- your email field. This brings email field into the rule's scope, otherwise your rule can't see the email field. This part is not possible to achieve in Actions section of a rule without "Conditional Rules" module.

And in the end - nest "Send Email" action under IF condition and you should be good to go.

  • Thank you for your help on this. The real issue was that my field_business was not being recognised as a multiple value field. Once I selected the correct data selector "entityform" instead of "entityform:type" the field was allowed to be added as a loop. I managed this without the conditional module, thank you. – Collins Nov 28 '15 at 16:02
0

The real issue was that my field_business was not being recognised as a multiple value field. Once I selected the correct data selector "entityform" instead of "entityform:type" the field was allowed to be added as a loop.

Once I fixed that stupid mistake the rest was simple!

{ "rules_pinboard_emails" : {
    "LABEL" : "Pinboard Emails",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "entityform" ],
    "ON" : { "entityform_insert" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "entityform" ], "field" : "field_businesses" } }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "entityform:field-businesses" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "mail" : {
                "to" : "[list-item:field-business-e-mail]",
                "subject" : "New Enquiry",
                "message" : "You have received a new enquiry, please login to your account to view.",
                "language" : [ "" ]
              }
            }
          ]
        }
      }
    ]
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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