Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Moving Notes to Containers by Key Attributes
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1215788103

Message started by Michael on Jul 11th, 2008, 10:55am

Title: Moving Notes to Containers by Key Attributes
Post by Michael on Jul 11th, 2008, 10:55am

Please excuse me if this topic has already been started. I am a newbie and part of the difficulty in being a newbie is not having a vocabulary of sufficient complexity to search topics with any kind of percision.
So here it is...is there a way to craft an action or rule so that when you assign a particular criteria to a note, it will automatically be "moved" into a container meeting that criteria? Like, I have a household inventory with containers representing furniture, applicances, electronics, etc. I would like to give a prototype note "possession" a key attribute entitled "type". When I create a new note representing a particular possession, when I assign a type to the note (e.g. TV = electronics), the note is moved into the appropriate container.

Title: Re: Moving Notes to Containers by Key Attributes
Post by Mark Bernstein on Jul 11th, 2008, 11:24am

The Container attribute will do this. You might use a rule such as:

    if(type="electronics"){Container="/house/electronic devices";}

Another approach -- perhaps more idiomatically Tinderbox, would be to create an Agent that looks for type=electronics.  This doesn't move the original note, which stays where you put it; instead; it makes an alias inside the agent.

The other Tinderbox idiom to consider it reversing the sequence: you move the note into /house/electronic devices, and the container automatically sets "type="electronics".

Title: Re: Moving Notes to Containers by Key Attributes
Post by Mark Anderson on Jul 11th, 2008, 11:51am

Ok, we have a string attribute 'Type' and we'll add a Boolean attribute 'Categorised' (name doesn't matter overly and purpose will become clear).

Now make an agent with the query (AgentQuery):
(Prototype="possession")&(!Categorised)&(Type!="")
..and action (AgentAction):
Container=$Type;Categorised=true;

Now, the agent first finds only notes that have the prototype 'possession' and withing that only notes where Categorized is false (we done need to do this task more than once per note!) and within that group notes that have a value for Type. Note how we structure the query so we limit the scope of the quote - not al notes will be possessions so we're note interested in those. Tip - the default value of a Boolean attribute is false (unticked) and note that the true & false values must be written lower case

So, the agent finds the note(s) that need moving. First it sets Container to the desired name, using the Type attribute value from the note being processed. Then it sets Categorised to 'true' thus stopping the agent re-processing this note in subsequent agent cycles.

Assuming you've an Outline view open showing all these notes, you'll see that the process appears on screen as if it takes 2 steps. What's actually happening is that as soon as the agent finds the note and sets the Container, the original note moves but the alias remains in the agent. On the next agent cycle, as Categorised is no longer false, the note no longer matches the agent's query and the alias is removed. Without the Categorised attribute (or whatever name you use) the agent has no choice but to re-run the actions it has already carried out in the previous cycle. As your TBX grows such unneeded repeat actions becomes wasteful though you're not likely to see a dip in performance unless the TBX file gets very large and your agent is processing a lot of notes. Still, it's better to use efficient procedures from the start.

My understanding is that if a value is set for Container and that note doesn't exist, then a new note of that name is created. In my test for this that didn't work (not sure why!). In general i'd advise you set up the containers in advance.

There's more polishing that could be done but that should get you started. Good luck...  

[Mark B's answer beat me to the draw - those suggestions are equally good. In TB there's usually more than one way. By not using an agent you don't need to consider excluding the notes you've already processed to the right container]

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.