Score:0

With Rules, how do I use variables with Calculate and Set a value actions?

us flag

Let's say I have an Entity with a custom integer field added. Let's call the field Global Total (field_global_total)

On some event, I want to

  • get the existing value of that field and store it in a variable

  • get the value of another integer field (from another entity) and store that in a variable

  • add the two variables together

  • save that sum as the new value of "Global Total"

Ultimately I want to learn this generically so I can build more complex rules. For example, I don't know how to create a variable, but when I do, is that variable confined to the scope of that rule? Or can I pass it around to any subsequent rule? And if I can, how do I access it in other rules?

But if it helps, this is my specific use case.

My goal is, in Commerce, I have Product A. Product A has an integer field called "Total Sold to Date" (field_total_sold_to_date). Let's say that the current value is 15.

Event

Item is added to cart. Quantity field is updated to 20. User checks out.

Condition

Entity has field

Action

-- get Quantity value and store it in variable 'this_quantity'

-- get Total_sold_to_date value and store it in 'ttstd'

-- add the two together

-- save the entity so that the sum is the new value of the product's field_total_sold_to_date value

Please note that I do not want to use an extra module like compute fields or math or commerce reports. I feel like this can be done out of the box. Thanks!

us flag
I'm having trouble finding tutorials or complete documentation about the Calculate a Value and Set a Value selectors for Rules. If you have any, please post them here in the comments.
pinueve avatar
mx flag
built components, first component, calculate anything you neeed, and return result, second component, same thing, now in your rule call your comonents, since both returned a value, in rules do: a+b=c
pinueve avatar
mx flag
search in this tutorial, its easy, goog luck https://www.youtube.com/watch?v=QL1Rp69Lq80&list=PL84B6FFA4F7ACAD57
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.