I have a note called “Top”, I add children notes named “uno”, “dos” and “tres”
Using the $OnAdd action, I was hoping to have Top automatically create a link to the children notes.
Here is my $OnAdd action code for the “Top” parent note.
The OnAdd code is run on the new children. You are asking them to link to their (non-existent!) children.
You want to look at something like linkFrom(scope[, linkTypeStr]). In v9.5.2, this code in $OnAdd makes a basic [sic] untyped link from the container to the new child:
an existing note is moved to the current container, either via manual drag or via action code.
a new note is created as a child of the current container (eve if it is the first child to be created for a note that isn’t yet a container)
Little used, but there, is an OnRemove action too. It runs, unsurprisingly, on a child note when it is removed from the current container. Note: deleting a child note is not a removal event as there is nothing upon which to act.
Where are you looking in aTbRef and not finding these pages?
That’s not snark, I’m just genuinely confused at how people can’t find things like the above and wondering what i’m doing wrong. Is it a terminology mis-match?
You are right! not sure how I missed it. right there in front of my eyes. I missed it.
ATBRef is indispensible. I use it everyday and learn something, each and every day!
Just as a side question - are the square brackets a misspelling there? I know it shows like that in TBX help as well. However, the formula works without them and the first one is in an odd place before comma.
the [square brackets] are an, unofficial, standard notation in code documentation. Anything in square brackets is optional, i.e. you don’t have to use it.
Thus you can generate a link from ‘Note A’ with no link type (i.e. type is ‘untitled’):
linkFrom("Note A");
Or, to the same but with a type ‘explains’:
linkFrom("Note A", "explains");
As, in a default document there is not per-defined type ‘explains’, this is also added to the documents’s defined link type.
It’s simply not possible to document in detail, every variation in every context. For instance, aTbRef expects the reader, if they don’t already know, what scope implies or else follow links that explain it. So informed they will understand why only one of these uses quotes:
linkFrom("note A");
linkFrom(children); // designator names are not quoted