Tinderbox Forum

Rule for filling note attribute with $ID of other note linked to it

I spent the whole Sunday reading aTbRef and trying to implement it for my project, but I’m stuck and don’t know why, so I decided to come here and ask for help from fellow TBX users. What I want to achieve:
If Note A with $Prototype=“pBClaim” links to Note B (same prototype) with “Supports” linkType, then Note B’s $ClaimSupportsID is filled with Note’s A $ID.

If Note A with $Prototype=“pCEvidence” links to Note B ($Prototype=“pBClaim”) with “Opposes” linkType, then Note B’s $EvidenceOpposesID is filled with Note’s A $ID.

What I’ve tried (and is not working):

$ClaimSupportsID=collect_if(find(linkedTo(that),"Supports"),$IsPrototype==false & $Prototype="pBClaim",$ID);

$EvidenceOpposesID=collect_if(find(linkedTo(that),"Opposes"),$IsPrototype==false & $Prototype="pCEvidence"",$ID);

There are more combinations, but if I can understand what I’m doing wrong, then I can figure out the rest by myself.
Here’s my TBX file:
TBX-file.tbx (574.5 KB)


Hi. Sorry you are stuck and thanks for offering a test file. The code in question is all in the $Rule of the 3 prototypes ‘pAQuestion’, ‘pBClaim’ and ‘pCEvidence’.

Recall that for linked To() (see):

Returns true if the current note links to an item or group of items; this is optionally filtered to only links of type linkType . Put another way, “Does an outbound link exist from the current note to item(s) ?”.

and linkedFrom() (see):

Returns true if the current note is linked to an item ; this is optionally filtered to only links of type linkType . Put another way, Does an inbound link exist to the current note to item ?".
OK, in this code the find() query


If the text above is runs in the $Rule of Note A then the value of that is $Path(“Note A”).

“Does an outbound link of type “Supports” exist from the current note to ‘Note A’ ?”

The find() tests every note in the document. Let’s assume for a moment, the first note tested is ‘Note B’. At that point the question resolves to:

“Does an outbound link of type “Supports” exist from the ‘Note B’ to ‘Note A’ ?”

I don’t believe that’s really what you want. Let’s try any write your earlier statement in more general logic:

If Note A with $Prototype=“pBClaim” links to Note B (same prototype) with “Supports” linkType, then Note B’s $ClaimSupportsID is filled with Note’s A $ID.


If a Claim-type note links to another Claim-type note AND that link is of link-type “Supports”, then the $ID of the link’s source note is written to the $ClaimSupportsID of the destination link.

If so, then your linkedTo() test above is the wrong way around. But I’d note at this point you have way to much part-/un-tested code running. At best it is making noise and at worst it is workng against you. So, lest migrate all the rules into ‘Code’-prototyped notes: the prototype ensures the code isn’t mangled and the move stops unwanted code running. To check where rules where, I turned on column view:

Aha! There are at least two notes using locally edited rules that should be inheriting from their prototype. Plus, two notes have a locally set rule (the same one) whose purpose I can’t work out as the is no note named “TbxConfig”.

The ‘List of Questions’ agent has an odd Action. A String-type attributet can only hold zero or a single value so this code is pointless:


As within the same action cycle, $Question is set to no the value and to a value. Here all you need is:


You only need to set a String to empty if you are going concatenate (add to) the existing value with additional data, such as in a list.each(){} loop—which is not the case here.

I note your Oppose/Support attributes are List-type, which allow duplicate entires. As they hold note ID which by nature are unique, why would you want the potential of duplicates. I would make these Set-type. For instance, a given piece of evidence may oppose a claim, using an ‘Opposes’ type-link. Surely it does this one (or zero instance) per evidence/claim pair. does your method allow evidence to both support and oppose a claim; potentially it seems it should but i’m not usre you’ve allowed for this.

But, by trying too many (automation) thinks are once

I suggest starting over, working first and only with one piece of the puzzle at a time, e.g. an evidence note opposes a piece of evidence. Also properly map out the evidence/claim/question paths. Can evidence refute other evidence? Your automation/linking model must allow for any path that occur.

Even with just the two orphan rules running Tinderbox is runnin g at max CPU due to poorly considered use of find(). If all rules are polling all notes all the time, your CPU fans will be on 24/7!

OK, out of time to look at this further. I think the linkTo/Form approach is wrong but I’ve not time to describe other approaches. But, do look at Link Actions. @satikusala has a tutorial using these but i’ll have to ask someone else to find the link.

Here is your file, as discussed above: TBX-file-ed1.tbx (568.8 KB)

I strong suggest you reset all the $ClaimOpposes, EvidenceOpposes, etc., series of attribute values and work up the chain. Do one small_ piece , e.g. ‘evidence opposes’ at a time. Test fix, and move working code yo a new clean TBX. Then start a different small test, in a new test note, fix, migrate code tech. Otherwise, you’ll drown in false stats like the non-inherited rules seen above.

Thank you for the time spent and effort you put into writing this reply! I will do as you say (above all: “I suggest starting over, working first and only with one piece of the puzzle at a time”, “Do one small_ piece (…) at a time”) and then come back here to report my results!
Thanks again!

1 Like

I’ve finally made it and want to share my solution with others, just in case that someone may find it useful in their projects! In retrospect, I had to deal with 3 main issues:

  1. What exactly is my goal and what are the logical steps that I have to follow to achieve it i.e. How to tell Tinderbox what I want.
    The model I wanted to implement is based on Joel’s Chan Roam Research Discourse Graph, but to make it clearer for myself how the model would work in TBX, I’ve recreated it visually in TBX:

  2. How to send information to Note B that Note A is connected to it with a particular LinkType.At the start, I’ve tried using Rules or Agents, but I decided to take @mwra 's advice to take a look at Link Actions. Sending information through links with Link Action was quite an easy procedure. But it also involved resolving another issue…

  3. Deleted Links. Because deleting link (unfortunately in my case) doesn’t have a reverse effect, I had to make a Rule/Edict that would go to every note with certain $Prototype and check if the links are still there, and if not, delete information send earlier (in my case Name of note in Set Data Type attribute).

Sorry for all the typos and grammatical mistakes! :wink:
@mwra I want to thank you again, for all of your tips and suggestions!

My TBX project file (check Code container for Rules/Link Actions):
Question_Claim_Evidence.tbx (125.4 KB)
Question_Claim_Evidence_v_1.1.tbx (127.5 KB)

Edit.1: Name of the fourth vertical Adornment should be “Note B’s searched Attribute value=Note A’s $Name” not the other way around, nevertheless code works how it should :wink:
Edit.2 Made some corrections based on suggestions from @TomD


Great work Arek.

One suggestion, in your link code, I am not sure if you are intending to overwrite the sources value if you were to link a 2nd or 3rd Claim prototype.

if($Prototype(destination)=="pQuestion" & $Prototype(source)=="pClaim"){

A tweak may be:

if($Prototype(destination)=="pQuestion" & $Prototype(source)=="pClaim"){

In that way, you keep existing values in your destination. Please keep us updated in your Joel Chan comes to Tinderbox modeling. Great stuff, my man.


Yes, you’re right! I will make the corrections you have just suggested and reupload the file! Thanks for the feedback :wink: