2

I'm having a Field Collection 'My List' with two fields: 'Amount' (integer) and 'Date' (date). I often count the 'Amount' items with Rules like this:

  • Add a variable: Parameter: Type: Integer, Value: 0, Provides variables: Sum
  • Loop over [node:field-my-list]
    • Calculate a value: Parameter: Input value 1: [sum], Input value 2: [my-list:field-amount], Provides variables: Result (result)
    • Set a data value: Parameter: Data: [sum], Value: [result]

As setting up this loop every time takes quite some time, I thought that creating a Rules component (action set) would make things a lot easier. I tried this:

  • Data type: List of field collection item items, Label: List, Usage: Parameter.
  • Data type: Integer, Label: Sum, Usage: Provided.

Creating a loop (Parameter: List: [list], List item: Current list item (list_item)) works, but there's a problem when I try to calculate the value "Sum + List:item". Namely, I can only select list:0, list:1, list:2 and list:3 as "List:item". That doesn't seem to be right.

How can I correctly select an item from the list and use it in the calculation?

  • Hey Jeroen, your paragraph near the end with "Creating a loop (Parameter: List: [list] ...")" appears tough to understand. If you still remember your question (from over 2 years ago), can you think of something to include an export of your rules component where you were struggling with? PS: I'd also change "action" to "Component" in the title of your question. – Pierre.Vriens Nov 22 '16 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.