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

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.


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


Entity has field


— 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!