2

I'm using profiles 2 and have (one or many) taxonomy terms that can be selected by a specific profile type. I have a webform that also has this taxonomy term in the select list. When the webform is submitted, if it matches one of many taxonomy terms in any of these profiles I want an email sent to those profiles. I can't figure out how to get Rules to do this. Any help is appreciated.

This is what I have so far. I just have it posting a message right now to test, but I want it to email, but I can't find the data I need to compare in the Rules.

{ "rules_webform_email" : {
"LABEL" : "Webform Email",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "webform_rules", "rules" ],
"ON" : { "webform_rules_submit" : [] },
"IF" : [
  { "webform_has_id" : {
      "form_id" : [ "form_id" ],
      "selected_webform" : { "value" : { "webform-client-form-3" : "webform-client-form-3" } }
    }
  },
  { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "webform" : "webform" } } } }
],
"DO" : [
  { "drupal_message" : { "message" : "Test submit webform\r\n[data:project_type-value]\r\n[data:project_description-value]" } }
]
}
}

The project_type is the taxonomy term in the webform. I need to compare it with the field_service_provided (Term Reference field to the same taxonomy vocabulary) in the Profile.

  • please include an export of the rule you have so far, so that we just have to answer with how to correct or complete it ... FYI: should be easy ... – Pierre.Vriens May 14 '17 at 6:10
  • Welcome to Drupal Answers! Please note you cannot change the meaning of a question after it got answers. This would invalidate the given answers, and it is not allowed. – kiamlaluno May 17 '17 at 8:15
2

Even though your question doesn't say so, from the format of your exported rule it's clear it is about D7. A possible answer to your question is by replacing the Rules Action in the rule you already have, and by also using the Views Rules module, as further detailed below.

1. About the Views Rules module

The Views Rules module makes Views data available in Rules, enabling intuitive rule configuration for dynamic data. Some details from its project page:

... provides two types of elements in Rules, configured with a "Rules" view display:

  • Views loop: A views loop is similar to a regular Rules loop, but allows looping over rows of view results.

    enter image description here

  • Collect view result rows (action): This action collects each variable in all view result rows into list variables for use in Rules.

Tip: When selecting the data type for variables in the view, if the field is an entity identifier (e.g. Node ID), you can set the data type to the entity type (i.e. Node) to directly use the variable in Rules as an entity!

2. Create a view of display type 'Rules'

After you enable the Views Rules module, you can use Views to create a view of those users that you want to send an eMail to. Add of view of display type Rules (important, that's the key to make it work!). Here is how you can add such display:

enter image description here

Next configure the row variables, by using the link that says "edit field info", as shown here:

enter image description here

You probably want to use one or more of the variables similar to those that are shown in this screenprint:

enter image description here

3. Create a rule using the view of display type 'Rules'

Replace the Rules Action in your current rule, using these guidelines:

  • Use the link that says Add view loop to add a Views loop, and select the "Rules" display created in the previous step.
  • Configure the parameters and variable names.
  • For each user contained in your Views loop, perform a Rules Action "Send an eMail", using the variables you configured at the end of the previous step (you may have to revisit the previous step to add more similar variables there if needed). If you created the Rules row variables as suggested in the previous step, your actual eMail can use tokens such as [usermail:value], [username:value], etc.
  • Thanks Pierre - I had also considered doing it this way but couldn't get my view to work properly. I can get the view to show all the information for all profiles but I need to just get the ones that have matching taxonomy terms, or can I set that part up in the rule? – Sharon Dankwardt May 15 '17 at 20:16
  • @SharonDankwardt How many taxonomy terms do you have, just a few, or dozens of them? If you only have a few, you could possibly create a separate Views display for each of those values (which you hardcode as a filter in each Views dispay), and then combine that with the Conditional Rules module so that within your Rules Action you select the appropriate view based on the value of the taxonomy term. Could that be a aid solution? Btw, are you aware of this? – Pierre.Vriens May 15 '17 at 20:33
  • I have 19 terms right now, but that could grow. I was thinking I could use contextual filters on the view but couldn't figure out how to get that to work. i had also considered using a global text compare filter but couldn't figure out how to compare one of a list. – Sharon Dankwardt May 15 '17 at 21:48
  • So.. I've got a view for one of the taxonomy terms that lists all matching profiles (I know I need to make the rest but I can't get one to work yet). I've got conditional rules. How do I get the taxonomy term on the webform to do the comparision? – Sharon Dankwardt May 16 '17 at 21:13
  • I swtiched to an entity form as I thought it might be easier. This is what I have so far but only saw the first message not the second one. – Sharon Dankwardt May 16 '17 at 21:31

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.