Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
kaizerking CreditAttribution: kaizerking commentedyes, 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.
Comment #2
tim.plunkettSupport requests aren't major, sorry. I've never used Rules with this module.
Comment #3
acrazyanimal CreditAttribution: acrazyanimal commentedI 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?
Comment #4
areynolds CreditAttribution: areynolds commentedThanks 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...
Comment #5
dimsum CreditAttribution: dimsum commented@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?
Comment #6
areynolds CreditAttribution: areynolds commentedOff 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 :)
Comment #7
AlexanderPop CreditAttribution: AlexanderPop commentedI 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" ]
}
}
]
}
}
]
}
}
Comment #8
tjferre CreditAttribution: tjferre commentedIf you had an unlimited value field collection, how would you do a data comparison?
Comment #9
AlexanderPop CreditAttribution: AlexanderPop commentedunlimited 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
Comment #10
tjferre CreditAttribution: tjferre commentedCould 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
Comment #11
AlexanderPop CreditAttribution: AlexanderPop commentedI gave example above. you need try it adopting to your fields. after testing - put here data what you did and what you got
Comment #12
benchesters CreditAttribution: benchesters commentedCan 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
Comment #13
plk83kevin CreditAttribution: plk83kevin commentedMy 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.
Comment #14
atpaust CreditAttribution: atpaust commentedAny new progress on #12 (benchesters commented about a year ago)?