Thanks for the clarification. Yes, you have populated the prototype’s OnAdd action ($OnAdd).
So, for any new child note of a note using that prototype or any note dragging under that note (i.e. making it a child), the OnAdd with run once and once only.
So the apparent failures are likely the children already existing. A temptation is to move the OnAdd code to an Edict or Rule. You could, but stop to think. You only need to set $Location once. Plus, I’m guessing most (child) notes don’t move much (I may be wrong!). so, you real problem is to find all notes that should have a $Location value but don’t, then set those notes’ $Location once.
The answer is an agent. The query needs to find all notes whose parent’s prototype is of [name] (I don’t know that so we’ll call it “X”) AND for which there is no $Location value. For those notes we then set the $Location, which then causes the note to no longer match the query—a self-emptying agent.
The agent’s query:
$Prototype(parent(original))=="X" & $Location==""
Agent action:
$Location=$Course+" - "+$Chapter+" - "+$Subtopic;
Now make the agent and let it run. It should initially add a lot of aliases which then disappear as all the notes that need a $Location value now have only. Once that has happened you can delete the agent as any new notes added to the document will trigger the prototype’s OnAdd.
In the query, why $Prototype(parent(original))
? Well, the parent of a note and the parent of any of it’s aliases differ. By saying parent(original)
we are being explicit that we want the parent of the note, or if testing an alias, the parent of the alias’ original note. It might not be needed here but as i’m working without a test file it’s a little harmless overkill and gives us another free action lesson!
Semicolons in code
Agents. Agent queries never need a semi-colon at the end and should not be given one, though Tinderbox is clever enough to ignore them if you do.
Actions (e.g. OnAdd). These only require a closing semicolon if there is more than one expression (complete action) as the semicolon tells the Tinderbox code parser, "action #1 ends here, run this code then come back for action #2, etc.).
So:
$Color = "blue";
//or
$Color = "blue"
But:
$Color = "blue";$Badge="ok";
//or
$Color = "blue";$Badge="ok"
Note that the ending semicolon is optional, but in the second case with 2 actions the semicolon must be added between the two actions.
HTH