Seems to be a very interesting module to bridge views filtering and rules functionality, but it's a bit of mind wrap — would love to see a video or explainer of example use case to better understand where this might be of use.

And thanks for giving back!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zhangtaihao’s picture

Unfortunately I can't really imagine off the top of my head a simple example. I would say this module is useful for batch tasks, but most simple batch tasks have other modules providing for those.

I developed this module to eventually provide for complex workflows (such as those to come in Portables). You could have a content type "Publication", with some bibliography fields and an online identifier field to indicate for which publication to fetch details from an external publication source. You then create a view (with a Rules display) to list the node ID and online identifier for all publication nodes filtered by last updated time outside a 24-hour window. Then, you would create a Rules component with a view loop (using the created view) to list all publications to update and execute an action to fetch publication data using the online identifier and sync to the publication node (identified in the view row). Given the component, you could then use Rules Scheduler to create a periodic fetch. This workflow updates all publication nodes with external data at least every 24 hours.

To be honest, I'm still working through the finer points of Portables in order to simplify the site builder's perspective of the workflow. In any case, Views Rules allows arbitrary tasks supported by Rules to be executed on any set of parameters that can be listed by Views, controlled by Rules.

Of course, if anyone else comes across this and would like to contribute some more examples of how Views Rules might be used, I'm all ears.

mitchell’s picture

Thank you so much, zhangtaihao.
Views result data is now really available to Rules!

I have two examples.

1) Simplified example to see if/how it works:
In node.view.txt and view-rule.rule.txt, there's a view with 10 nodes, and a rule with a 'view loop' that displays these 10 nodes' ids in a system message when viewing a user page. (I would like to make those into more easily sharable components, but quick and a little dirty is fine for now.)

2) Not as simple example:
This is an XML data syndication and web scraping idea I had about a year back (before Rules XPath Parser and after Feeds XPath Parser). It's only now come to fruition :-D, but a couple pieces are missing which I can put in separate issues. drupal_planet-rules.view.txt reads the Drupal Planet RSS feed using Views XML Backend and then planet-message.rule.txt shows their titles and urls. It could also very easily be modified to create nodes and populate their fields.

I'll work more on the examples and docs for this later (suggestions welcomed), but now I'd like to spend some more time on Rules UI Factory. Thanks again, zhangtaihao!

zhangtaihao’s picture

Thank you for the kind words, mitchell!

eliaspallanzani’s picture

ahem... i've tried the planet-message.rule_.txt, but for me don't work. When import the rule:
Notice: Undefined index: DO in RulesContainerPlugin->importChildren() (linea 2167 di /home/tcbkitrp/public_html/sites/all/modules/rules/includes/rules.core.inc).
Warning: Invalid argument supplied for foreach() in RulesContainerPlugin->importChildren() (linea 2167 di /home/tcbkitrp/public_html/sites/all/modules/rules/includes/rules.core.inc).

i've a rule xml backend and i've imported some data from html page.
the view has 3 contextual filter.
i set a rule to loop the view's result and creates new entity, then set new entitye's field with data from the view, but don't work and i don't understand:
1. viewloop or "Collect view result rows"?
2. what data type for contextual filetr?
3. waht data type for field? text, dom element, list of text or list of dom? or list of list??

Yuri’s picture

After trying multiple times, I still don't understand how this should work in Rules, the project page explains until "[Do what you want with the newly available variables]" but that is where i get stuck.

I have a list of nodes (content type 'Article')
For each article X that is flagged:
- create a new node (content type 'Publication') with title 'Publication:*article name*'
- Set the entity reference field of the Publication to the article X.

This should result in a list of new Publications, each referencing an article.

I have no idea how to accomplish this by using rules view variables here..

metroecho’s picture

I am trying to can schedule a series of five to ten emails to be sent to a list of contacts one every so many days. The I deal would be to be able to have a view of a taxonomy list of nodes sorted by taxonomy term then choose the term to send by like introductory emails. Then input an email or select a CRMcore contact and it would then send one node each three days until all nodes are sent.

I have VBO, Views Rules, Views periodic execution installed. You are correct there is not much good documentation. I am surprised that a module is not out there for sending a series of emails for Drupal 7.

I can't think of any better tool for reacting to a sales prospect than to say to them, I will send you a series of emails that will better describe our product, and set an automated email sending program that can last a few weeks. They get an email every so many days in a series or steps of information. The prospect is keep fresh over time, and taught about your company systematically over time.

I have been trying with different settings all day to no avail... any suggestions ?

zhangtaihao’s picture

@Yuri:

You will need a view of 'Article' nodes filtered by 'flagged' with a Rules display with the article nid as 'Node' variable (and optionally article title as 'Title' variable). You can then create a rule with a view loop to create publication nodes and set article reference field to the specified article.

Screenshots attached.

zhangtaihao’s picture

@metroecho: Your requirements seem a distinctly CRM use case. Have you perhaps tried dedicated CRM solutions like CRM Core or RedHen? Also, there are paid services like Salesforce with which Drupal integrates.

In any case, I once built a contact manager in Drupal 6 with just VBO and Rules (1.x), run by the built-in Rules scheduler. Basically, a scheduled rule runs a VBO that lists specified contacts and messages and runs a separate rule to send emails with Mime Mail.

metroecho’s picture

Yes, I am trying to do this with CRM core. Thanks for the info, I will try your suggestion above. I understand that the new version of CRM core may be coming out next week and will have this incorporated into it.

korzh-nick’s picture

Hi!.
Thank you very much for the desired module.
Please tell me how to use context filters. I need to insert a field into the material group to which it belongs. The arguments that I put work
on the page (in the view of EVA), but do not work in the rule.
reason this :
view:

/* Contextual filter: OG membership: Group ID */
$handler->display->display_options['arguments']['gid']['id'] = 'gid';
$handler->display->display_options['arguments']['gid']['table'] = 'og_membership';
$handler->display->display_options['arguments']['gid']['field'] = 'gid';
$handler->display->display_options['arguments']['gid']['relationship'] = 'og_membership_rel_group';
$handler->display->display_options['arguments']['gid']['default_action'] = 'default';
$handler->display->display_options['arguments']['gid']['exception']['title'] = 'Все';
$handler->display->display_options['arguments']['gid']['default_argument_type'] = 'og_context';
$handler->display->display_options['arguments']['gid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['gid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['gid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;

rule:

       "USING" : { "gid" : [ "node:nid" ] },
korzh-nick’s picture

FileSize
3.01 KB
64.32 KB
78.76 KB

Did not understand how to do it using the contextual filters, made by comparing the data in the
rule. Now it works

zhangtaihao’s picture

I've opened #2015647: Basic tutorial for simple example for reference. I'm caught up doing something else at the moment but I'll try to get to it.

In the meantime, feel free to write something in the handbooks if you already have something handy.

gtothab’s picture

Hey,

Thanks for the great module. I don't know how to quite use it but I can already feel the power!

When users of my site sign up they can choose one or more interests by way of profile 2 module. Interests are taxonomy terms. They can also opt in to "Send me posts related to my interests via email" by checking a box (also profile2).

I need a way to send users that checked the box an email once a week with a list of that past week's posts that are tagged with any of the interests they chose when signing up (they can select multiple interests). I figure I need to create a view that includes ALL posts for the past 7 days (simple enough). I probably need another rules view that lists the users who have opted into the emails. But I don't know how to get from there to actually filtering the list of posts for each user so that they are sent only those posts that are tagged with their interests.

Does anyone have an idea of the steps I need to take to achieve this?

Thanks!

zhangtaihao’s picture

Your need is probably somewhat different from what you initially thought. The view of all posts tagged by interest is only indirectly related to the rule containing the view loop to send users related posts.

Essentially, this module will allow you to loop through users to send each a message. The message is basically text, not behavior, and is what needs to be built separately. So, your view loop display will need to provide these fields:

  • The user email (or the uid as user entity if you'd rather access the email field in the rule).
  • The message text field.

The view loop really doesn't need to care about anything else. One way to build the message from within the view is to use Views Field View, which allows to nest the output from a separate view (which can take simple contextual filters) into the parent view without affecting the enclosing query.

Note: if your site has a substantial number of users (say, 1000+), you may want to take care to heavily cache the "related posts" view and batch/queue messages since running the nested view and sending messages 1000+ times is very resource-intensive and may be extremely difficult to troubleshoot if an error interrupts the process.

ericwongcm’s picture

Issue summary: View changes
FileSize
1.09 KB
3.69 KB

I am trying to do something similar to @Yuri #5 using views_rules.
I am doing similarly to the way explained in #7.
But ONLY one entity is created instead of one every view row.

Attached is my view and rule I am testing this.
I have put two system messages within the rule to check that it is indeed looping through the rule that creates the entity.
I am using Ubercart order update as the event to trigger the rule but you can use any other trigger.

In my view, I use filter to require that the node listed must contain a specific field, Order ID. (you can change it to anything other field you want..)

Between the two system messages within view loop, the action I specified is meant to create comment entity for EVERY NODE that contains specific field, Order ID.

From the message shown, it is obvious that the view loop works and pass through every row but why the comment entity is ONLY created in the first loop but not the rest, i.e. I only see one comment entity created?

If anyone know what I am doing wrong, please comment.
This is a very useful module to automate tasks if I can figure out how to use it...

ericwongcm’s picture

I found what I did wrong... I need to add action to save entity as shown in #7 screenshot.

nithinkolekar’s picture

#7 doesn't work anymore because value[article] is not available in "set data value" and "add item to list". Both actions seems broken to get current value inside loop. (rules core issue #2947392: list-item:value not available for action "add an item to list" inside loop)