Tinderbox Forum

Boolean test not working in onAdd action

I have a ‘meetings’ prototype that contains a boolean called $Actions

‘meetings’ has the following onAdd action that isn’t working as intended ( If $Actions in meetings is true I want any children created to be of tasks prototype and if false to be of agenda item prototype

if($Actions==true){$Prototype="Task"}else{$Prototype="AgendaItem"};

I’ve tried combos of If($Actions){…} and if(!$Actions){…} etc but to no avail - The boolean state test seems to be ignored - not crucial but I thought it was going to be a fairly easy test :thinking:

Code in on OnAdd runs on the (new) child note. Thus:

if($Actions==true)

Is testing the new child’s $Actions value. But your intent is to check the $Actions for the container note, i.e. the parent of the new child. Which means you want to test if($Actions(parent)==true).

So broken out with line breaks to show the branching:

if($Actions(parent)==true){
   $Prototype="Task";
}else{
   $Prototype="AgendaItem";
};

The above works for me in v9.2.1, macOS 12.4.0

The OnAdd action is run when the note is created, or when it is moved into the container. So, if you make a note and then set $Actions to true, the OnAdd will already have run.

What you might want is an agent.

Query: inside(…your container…)
Action: if($Actions==true){$Prototype=“Task”}else{$Prototype=“AgendaItem”};

Perfect - Irritating I didn’t spot that - many thanks Mark A