Hi,

could you please explain how one should setup rules to achieve the following:

My field_collection has two fields:

* key
* value

I want to search by key and then retrieve the value (to compare it with something else).

Thank you,
Max

Comments

kaizerking’s picture

yes, there should be a document on this,
When I try to find the field i see lot of xyz_field-0:,xyz_field-1,xyz_field-2,xyz_field-03, I could not understand what does that mean,all have same label
If i want to select a field to match a condition how should i select?
I was trying to find a term field which is hierarchical, and multiple terms, saved only the deepest term in a field collection field to match a condition, I cant find it.The descriptions are all same and there is no way to find ,when i try to select the list keeps adding and there is no end.

tim.plunkett’s picture

Priority: Major » Normal

Support requests aren't major, sorry. I've never used Rules with this module.

acrazyanimal’s picture

I just did this today actually. To gain access to the field collection's fields you need to have a data comparison on the field collection's field-name parameter. This acts like most entities' type comparison and asserts that it is of a certain type. Thus, rules now knows which fields are attached to this field collection type and you can add additional conditions on the specific fields.

@maxilein: Not sure how exactly you want to do a search in rules, but if it involves using the load entity by property or id, then likely you will need a loop to loop over the returned results. Then, you would probably need to feed the field collection iteration item into an additional 'rules component' to do your comparison on field-name ... and the 'value' field.

Hope that helps a little?

areynolds’s picture

Thanks acrazyanimal, that helped a lot. I needed to drill down through a node to a field collection with a term reference field. To clarify this process for the kids at home...

  1. Create an "entity has field" condition on your Rule.
  2. For the "Data Selector," select the entity that contains the field (in my case, a node). For the "Field" value, select the machine name of the field collection in question.
  3. Go to your action. Using the "Data Selector" mode, you should be able to drill down through the entity in question to all the values contained within the field collection. In my case, the end result is "node:field-enrollee:field-school-district:0:tid"
dimsum’s picture

@areynolds Is there anyway to do this as a Conditions?

What i'm trying to do is:

- I have a Field Collection attached to User to record activities that award Points for the user. I called it Point History
- If a user is viewing a certain Node, I want to check if the Title of the Node is already appear in the Point History

I'm thinking of using 'is one of' comparison to compare the viewed node against the field collection values.

Can this be done?

areynolds’s picture

Off the top of my head, it sounds like that would be possible. You should be able to access the Field Collection as long as it has been referenced in a previous Condition, like the "entity has field" condition that I mentioned.

Let me know if that works for you and if not, what does. This does need some documentation :)

AlexanderPop’s picture

I have:
field collection field_parts
and as part of field_parts Field: field_part1 (select list)
also as separate normal Field: field_part_1_levels (select list)
I need after creating NEW node of this content type get data from ALL field_part1 items and be populated to field_part_1_levels (be selected according available items from field_part1 )
So I've created rule:
event: After saving new content
Conditions:
1. Content is of type: my_content_type were fields are
2. Entity has field: Field: field_part_1_levels
3. Entity has field: Field: field_parts
4. Entity has field Parameter: Entity: [node:field-parts:0], Field: field_part1
actions:

Loop: Parameter: List: [node:field-parts] List item: Current list item (list_item)
(inside loop above ) - Add an item to a list: Parameter: List: [node:field-part-1-levels], Item to add: [list-item:field-part1]

Hope it will help someone
{ "rules_node_create" : {
"LABEL" : "node create",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "node_insert" ],
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : {
"premiumcontent_page" : "premiumcontent_page",
"trialcontent_page" : "trialcontent_page"
}
}
}
},
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_part_1_levels" } },
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_parts" } },
{ "entity_has_field" : { "entity" : [ "node:field-parts:0" ], "field" : "field_part1" } }
],
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "node:field-parts" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "list_add" : {
"list" : [ "node:field-part-1-levels" ],
"item" : [ "list-item:field-part1" ]
}
}
]
}
}
]
}
}

tjferre’s picture

If you had an unlimited value field collection, how would you do a data comparison?

node:field-item:***:field-item-delivered

***=0,1,2,3,...
AlexanderPop’s picture

unlimited value field collection is exactly i had(have)
you do things with first field collection line
and loop action will dig through all lines you have

tjferre’s picture

Could you be a little more specific about how to go about this?

My goal is to check whether a checkbox is checked in each field collection item, then perform one action.

Thanks,
TJ

AlexanderPop’s picture

I gave example above. you need try it adopting to your fields. after testing - put here data what you did and what you got

benchesters’s picture

Can anyone clarify this for me at all please? What I want to do is trigger an action when one of the fields on my field collection is changed to a certain value. For example, my 'campaign' node has a field collection with a field called 'status' This status is a list containing 3 options; 'onboard', 'live', or 'dead'. When the field on a campaign node field collection is set to 'live' I want to trigger an action.

So I start by saying:

Events: After node is updated

Conditions: This is the bit I am struggling to work out as I cannot do a data comparison with this particular field.

Action: send email

plk83kevin’s picture

Issue summary: View changes

My case is when a workflow(join activity) create, than check the user credit(it is a value store in a contact type user_information, also in user_information have a field username = same as useracc name(system/login name), may be using the author name to search for the user_information which user is?) is available or not, if not direct it to another workflow state.

how can i do it ?

thanks a lot.

atpaust’s picture

Any new progress on #12 (benchesters commented about a year ago)?