How to update a variable in an activity diagram during simulation?

I am working on an activity diagram that contains several actions, each with a tagged value called i: int . This activity diagram has a context block named "context" with a value variable sum: int = 0 .

I want to update the "sum" during the simulation, such that

sum = sum + i

For example, after simulating this diagram, sum should become 5 (i_action1 = 2 and i_action2 = 3) 

 

 

Could someone provide guidance on how to model this? Specifically, how can I retrive the value of i in a clear and effective way? I tried with opaque action, with groovy code

sum = sum + ALH.getTagValue(this, “i”);

But it doesn't work, because "this" is the script, not my action. I tried also with this.getOwner() and this.getCaller() and self, but no luck.

Any examples or best practices would be greatly appreciated!

Thank you!