Stuck on rule syntax to change the attribute of a specific child note

Stuck on the correct syntax, here is a sample file for what I want… but cannot seem to make it work. I am missing something…..

I have a parent note with a rule, pseudocode: if the child note begins with “Te”, then color the $Flag = violet.

I cannot seem to make that happen. What am I missing? I think I might have used the child designator wrong but am not certain.

test - Rule to change flag of a child note.tbx (73.2 KB)

nb… I have commented out the rule code I had and left the document in a state which I wanted but cannot seem to get. try a new color to test…

Thanks in advance
Tom

We know about the child designator:

child

The designator child represents the oldest child (note) of the note currently in focus, thus the first as listed in Outline view.

So for the container ‘one’ in your test, it keeps checking the first and only the first child ‘uno’ which fails the test.

You want to iteratively and independently check every child of ‘one’ and do your test. Try this:

collect(children, $ID).each(aChild){
   if($Name(aChild).beginsWith("Te")){
      $Flags(aChild)="orange";
   }else{
      $Flags(aChild)=;
   };
}
1 Like

It all works fine. Thank you as always.
One Question which surprised me
if I use the Logical Assignment operator inside the iterator, like so, it fails with the iteration.
This works fine with $OnAdd: $Prototype |= “pNote”; but the iteration does not

collect(children, $ID).each(aChild){
    $Prototype(achild) |= "pNote"; //this does not work
    if($Name(aChild).beginsWith(“Te”)){
        $Flags(aChild)=“orange”;
    }else{
        $Flags(aChild)=;
    };
}

why? I would assumed it would work.
Thanks
Tom

Your loop variable is aChild, but you forgot to capitalize the C in the assignment

1 Like

ahhh…. rookie error. Corrected….but….

Still not working….

ok I corrected that, but it is still not behaving the way I thought it would. Perhaps my assumption is wrong but I thought $Prototype(aChild) |= "pNote"; would only apply a $Prototype IF there was no prototype. What happened with the loop variable is even if I set a prototype, in my case, I had already set a $Prototype as “pFolder” with the $Prototype(aChild) |= “pNote”; it did not respect it had a prototype and changed it to ‘pNote’.

However if I use '$Prototype |= ‘pNote’; on a single note, all works

here is the file…

Tom

test - Rule to change flag of a child note.tbx (135.7 KB)

Your example file acts as described which … is odd given how we understand the |= operator to work. I note this operator does back to v4.6.0 when things were simpler. This suggests that it may be the case that for |= (and possible similar operators) the left side is not fully evaluated. Thus:

  • $Prototype is "" (the doc default)
  • $Prototype(aChild) is set to "pFolder"

but if the left side of |= only evaluates the attribute and not the offset address (i.e. the (aChild) part) then you get the result you see.

I think this is one for @eastgate.

†. Interestingly this URL is valid but breaks the forum’s Markdown parser: https://atbref.com/atbref11/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/|=_i_e_logical_OR_assignment.html (I used code mark-up to fool the parser)

This may be a special case for $Prototype.