Tinderbox Forum

Mathematical operator "sum" question

Yesterday, I began to set up several note with $Bill (record type is number) attribute, which presents the number I have to pay in latter days. Then I created a agent with $Balance (record type is number) attribute to sum up all children notes with $Bill attribute. I set the code in agent shown below:

  1. query : all
  2. agent action : $Balance=sum(children,$Bill)
    No matter how hard I amend the code syntax, the agent’s $Balance still shows “0” in its column.
    Is there any problem with my syntax? Please give me some clues to correct that, thanks.

The problem isn’t about sum(); it’s about how agents work.

Agents gather aliases of notes that match their criterion. For example, if we want to gather all the notes in the document that have an outstanding balance, we could try:

Query: $Bill>0

This will gather aliases of every note that has a $Bill. Now, we’d like to know what the total balance might be. We can get that from a Rule on the agent:

Rule: $Balance=sum(children,$Bill)

Why a Rule and not an AgentAction? The agent action is applied in turn to each alias, and when it’s applied this is bound to the alias. The Rule runs once, and when it runs this is applied to the agent. So, the rule adds up all the bills for the agent’s children.

1 Like

Thank you so much, it works. And I think the concepts you described between agent action and rule are definitely clear.