Tinderbox Forum

Prototype and OnAdd Action

Thanks Michael - that’s what I tried - to have one prototype for my folders and be able to add a second prototype that will be assigned to all childs of this folder with the OnAdd method. “pPerson” is the name of the prototype I would like to assign to all children of this folder…

The OnAdd action


is equivalent to


where this is bound to the newly-added note. But that’s not what you want! You want to set $Prototype(this) to $AssignPrototype("Personen") – the note with the OnAdd rule.

The OnAdd rule is run when a note is added to a container, so what you want is:

1 Like

Great - that did it and I learned an important concept addressing the parent element :wink:

See more on designators, like this and parent as in the examples above.

1 Like

So, if I’m understanding you right, what you want is this, your parent, e.g. “Personen Folder”, to have one assigned prototype, e.g. “pFolder” and you want the children of this folder to have a different prototype, e.g. “Person”. In this case, you’d simply point your $OnAdd to the pPerson prototype like this, $Prototype="Person";. This is exactly what we covered in yestrday’s meetup: Meetup 18SEPT21 Lesson 1: Blogging [Basic] with Tinderbox - Setting the foundation.

yes and no :wink:
I want a prototype for all my folders (“pFolder”) but the children of different folders should become an individual prototype while still using the same prototype for the folder.
For example: I have one folder called “people” and one called “cultural studies”. Both will get the prototype “pFolder” and so the OnAdd attribute $Prototype=$AssignPrototype(parent);
For the folder called “people” the attribute AssignPrototype will get the value “pPeople” and for the folder called “cultural studies” the attribute AssignPrototype will get the value “pArticle”.
So I can maintain one prototype for all folders and still have an individual OnAdd action depending on the value I put into the attribute AssignPrototype.

maybe I can get another hint… :wink:

how can I retrieve the value of an attribute of a specific note with $Name="gPrototype" in my OnAdd action?

How can I retrieve the value of an attribute of a specific note with $name=“gPrototype” in my OnAdd action?

First, if I know there’s a top-level notes name gPrototype, I can get its value easily:


If I know where to find gPrototype, that’s easy too. Suppose I know the gPrototype is in a container “Fancy Prototypes”. I can refer to this note through its path down the hierarchy.

$MyString(/Fancy Prototypes/gPrototype)

Finally — this is gilding the lilly! – suppose we want to get the values of this attribute for every notes names gPrototype in a document where lots of notes have this name. (Don’t do this if you don’t need to!). The expression find($Name=="gPrototype) returns a list of the paths that satisfy this condition — the notes that are named “gPrototype”. So

$MyString(  find($Name=="gPrototype") )

returns a list of values, one for each note named “gPrototype”.

something is going wrong… I understood the concept using the designators (I think).
But still struggle with the syntax. The name of the note I reference is “gPreferences”. The path attribute shows “/gPreferences”. The attribute of this note I try to fetch is “gPersonProto”.

So I tried: $gPersonProto(/gPreferences);

But no value appears in my target.

SimpleTest.tbx (103.0 KB)

What is going wrong? Can you share a screen shot? When I tried doing something similar I got caught in some kind of circular reference and the prototype will always end up becoming “None” no matter what I tried.

you saw the demo file I attached?

Actually, I had not. Sorry, missed that. I just tried it and it is working perfectly for me. I love it, actually, and and am going to start using this immediately in my files. WONDERFUL idea. I clearly was not understand you earlier, sorry about that.

See here:
TBX L - Use an attribute with OnAdd to assign prototypes to Children.tbx (109.4 KB)

I added one twist.
I put a collect on the Prototype folder to pre-populate $AssignPrototype (which needs to be a Set).

This way i can just select from the list:

Great job!!! Really like this.

OMG!!! I’m so sold on this. :-). I have it fully integrated throughout my sales pipeline workflow right now. Perfect!

yes - it was a nice idea you had in our session yesterday - I’m just trying to understand same basic principles of TB9 :thinking:

You saw the folder called “ImAFolder” - that’s my current problem I try to solve…

I tried to get an attribute from a note by the name of the note. Didn’t work. And the preview is strange - the values for (A) and (C) should be the same - they are not:

I do like the OnAdd event handler a lot - most of the time I use the same prototype within a folder. Speeds up everything :wink:

Sorry, I don’t understand. Are you trying to pull in the value from the attribute JustATest into the $Text of the note?

If so, you’d say this:
^value($JustATest)^, to get the value from this note.
To get the value from another note you’d say ^value($JustATest("OtherNote'sName")^' or ^value($JustATest(/thepath/OtherNote’sName)^’. You need to be sure to use straight quotes.

the output in the preview is just for debugging.
What I try to solve is simple: get the value of an attribute of a note where I address the note with the path to the note:


(“gPersonProto” is the attribute I try to access, “gPreferences” is the name of the note)
I tried to write the value I got this way into an attribute of the folder.

P.S.: ^value($gPersonProto(/gPreferences)^ returns nothing too in preview

Oh… I see, I’m so sorry for being soooo dense. Give me five minutes and I’ll send you an example.

Sorry, got distracted with family…here you go.

You just string the action code. Here, in the attached I have the parent populating the new child’s $Organization.
SimpleTest.tbx (124.9 KB)

Hi Michael,
thank your so much for your help - and no need to hurry :wink:

your demo shows the same problem as mine. The preview shows:

I would like to see the value of $gPersonProto(/gPreferences) - not the code itself :wink:

Ah, yes, but you are seeing the value. The value of those flies is that value.

Try a different attribute. See here:
SimpleTest.tbx (126.1 KB)