Posted by Rucha on January 18, 2012 at 11:30pm
Hi,
I have a problem with the data compare condition and cannot seem to find a way to do it.
What I want : To create a rule which will compare the data entered via a text(current entry) with the same values already present in other nodes(old entries).
eg : Id : 6 ------- this is the value(data) the user adds in the page he is filling up before he hits a submit/save button
the rule should check if some other user has added the same value(6) for the same field(Id) of other nodes that were created initially.
Please help
Thanks!
Comments
Rule set and stuff
This can be done if you create a rule set (component) and then add the following into it:
1) Add a rule that, as an action, fetches entity by property. Fetch entities that have the given value for the given field, and limit the results to one.
2) Add a new rule in the set, and add a condition. Check if the first result from the fetched entities exists. (There is a condition "data is empty" which I think can be used for this. Note that the first item has index 0, not 1.)
3) Add whatever actions you need after this.
If you're looking for a way to make the field unique for each node, then I suggest checking out the Unique field module (http://drupal.org/project/unique_field). The approach above is useful for making more complex stuff happen.
Good luck!
//Johan Falk
**
Check out NodeOne's Drupal Learning Library! 250+ screencasts and exercises, for Drupal introduction, advanced configuration, and coding. Creative Commons license!
Rule set and stuff
Thank you very much Itangalo.
I don't know if you are still on this .. But what to do in the data selector for the step 1
Thanks again
Is there a way to do this with D6 rules 1.x?
Is there a way to do what you describe above in D6? Fetch CCK node by property?
Not really
There is no action that corresponds to "fetch entity by property" in D6.
When I had to do similar things in D6, I've used Views Bulk Operations and executed an action on all nodes in a view – but that is rather tricky. See http://dev.nodeone.se/en/learn-rules-with-nodeone-part-17-calling-a-vbo-... for a tutorial of how it could be done.
Good luck!
//Johan Falk, Sweden
All nodes
Does fetching entities with results limited to 1 really compare the value to all existing entities that fit the criteria? In my testing, it only seems to actually compare to a single entity, but my setup is a little bit different. I'm trying to check if all nodes assigned to a user (using an entity reference field) conflict with the scheduled date and time in the new node (using a date field). I fetch all entities where the assigned user matches the assigned user in the provided node with results limited to 1, then have a second rule in the component that checks if the date in the provided node conflicts with the date in entity-fetched:0. But, as I said, this only seems to check a single result. How can I extend it to all entities that fit the criteria in the first rule? I feel like I might need to set up a loop somewhere, but I'm not sure where.
P.S. I've worked out a solution where I call a component with 2 node arguments within another component's loop. I send it the provided node and the list-item node for every fetched node, but this seems to run very slowly.
Fetch entity in loop
I have same problem as Infinity in Totality. Second rule set doesn't see the results of "Fetch entity in loop". Is there any solution about this?
Data Comparision
Rules module doesnt compare data of user profile field with content field. Iam looking for the rule which after saving a new account compare user email address with node field called email id. Is there any way to do this