So you want the child to show the word count of the parent at the time of adding the note. Or do you want the current count.
I just want to have the same name as the parent node plus a number to make the name unique (to avoid identical names in one container, it doesn’t need to be the count)
As to pasting text into a container and it not firing the container’s OnAdd, I can’t replicate that. Until I have steps that reproduce the error, sadly I can’t help on that.
I just copy text (ctrl+c) and paste (ctrl+v) the text inside a container. Everything works fine but only the name doesn’t change. The name only changes when I cut (ctrl+x) and paste (ctrl+v) the node again in the container
So the children could be “note 1”, “note 2”, “note 3”. If I understand the constraint here is the sibling notes all have the same title ($Name) so we need to add something to make it unique.
In the latter context , you earlier solution, even if the code worked would fail as unless the container $text is altered between every note being added, $WordCount(parent) will not be adding a unique element to the rest of the new child’s $Name.
I still can’t replicate thus but I think I can guess the issue. You’re pasting some info into a container and letting the app name it. Separately, the OnAdd is trying to use the on-the-fly created $name and change it. This container OnAdd works, I think. I have a container ‘bin’ with this $OnAdd and with 2 existing children:
I still can’t replicate the case in red (above). I can only get that if no note is selected or the selection is outside ‘Test-container’. But, in those circumtances the new note is created in a different location, not our test container, and so the special OnAdd code is not used (as I’d expect). this also means that in outline view you can’t use this method for the first such child. Why? Because you can’t set focus on the non-existent child branch of a non-container (in a map though you can drill down to an empty child map and thus set focus.
In my test you’ll notice that with the test container selected and using ⇧+↩ to make a new child, i get the correct name but no text. For the next 2 cases I left the last sibling selected and blind pasted the string “The pattern requires configuration via its arguments.”, which for items #2 and #3 turns up as the $text of the note.
Please note, I’m not suggesting you are doing anything ‘wrong’, just that when using your description alone, I cannot reproduce the effect you show. So, we are doing something subtly different. FWIW, here’s my test doc: OnAdd-test.tbx (110.7 KB).
Using that TBX with and of the 3 siblings selected, you should get a 'Text-container 4" added. where it is inserted will depend on which sibling is selected. If no note in the document is selected, your clipboard text should form the $Name of a new note at root level as first sibling. If the container note “Testdrive” is selected then the paste uses the clipboard text to name a new sibling note to that container. If “Test-container” is selected then the paste uses the clipboard text to name a new sibling note to that container.
I did take some time to test if it was an (occasional) timing issue where the $Name value created from the pasted text was set after the note was created and was thus overwriting the name set by the code.
Other scenario that might occur but which I did not investigate:
Agents acting on aliases of the notes created in the container.
There is other code in the container rule, or in its edict that affects the child notes.
The container has a $Sort value set. I think this one very unlikely, but here in case
I think this might have been a minor typo in the OnAdd action — one small enough to be easily overlooked, but that interfered with the evaluation of the $Name clause. I tried this here, and it did work correctly.