Collection: calculations and changed/updated event?

I have a dynamic collection with an amount property.

On one of my pages, I need to calculate to total sum of all amounts in the collection.

I can easily compute the sum in JS by iterating each item and summing on the amount.
This has to be done whenever the collection is loaded/re-loaded.

Any way to get an event for a collection change of some kind?

/Henrik

OK, so I made use of AI and it did exactly what I would do - though it created in a page workflow without a trigger. So I can solve my problem by using this workflow on page_load and when ever the collection changes from within the page I can re-run the workflow. Unless one of you scream: Why don’t you use the smart “on collection loaded / changed” event (which I can’t find) :slight_smile:

You can use a formula, formulas are reactive and will react to stuff like collection change with re-computing the whole thing. You pass in a collection, do your counting and that’s it, that’s the magic you’re probably looking for. The reactivity is very powerful concept, but it also makes it easy to shoot yourself in a foot.

TLDR: Just move your JavaScript function into a formula.