Tinderbox Forum

Collecting an array of attributes and populate other note's attributes with it

Sorry if the title sounds confusing. What I’m trying to achieve is:

I have several notes with the following key attributes:

  • END
  • START_1
  • END_1
  • START_2
  • END_2
  • START_3
  • END_3

I want to connect three notes (a, b, c) to another note (COLLECTOR) and get the $START and $END of the first three to populate, respectively, the $START_1, $END_1, $START_2, $END_2, $START_3, $END_3 of the last note (COLLECTOR), when the first three are linked to it through an outgoing link named “LINK”.

In the attached file, I am doing it for the link between “FIRST” and “COLLECTOR”,

if (linkedFrom("*","LINK")) {

but I’m trying to write an action code that, when all three notes are connected to “COLLECTOR”, it would:

  1. collect the $START and $END of notes a, b, c
  2. sort the collected data by $START
  3. assign the $START - $END pair with the earliest $START to $START_1 and $END_1;
    then assign the next pair to $START_2 and $END_2 (second note with earliest $START);
    finally, assign the pair with the oldest $START to $START_3 and $END_3.

Hope this makes sense!

LINKTO.tbx (57.2 KB)

Just for understanding – are you looking for a rule for a note whose method is to iterate through that note’s inbound links of type “LINK” and then, linked-note by linked-note, populate those attributes?

I assume this has something with tracking dependencies in a project?

Others more adept than I can chime in on the feasibility of this, and method, if feasible.

Just to say it – it might be easier to do this if the three notes were children of the “collector” note.

And you might consider using a table expression on that container note, on a map, to show the date data collected from the children.

You didn’t ask for alternatives, but some times it is helpful to consider that there is more than one way to peel turnips. My own view is that collating data via these link-based actions can be very fragile and very difficult to debug.

Thanks Paul. Yes, it’s like you say; and the purpose is not task management (although it could fit on it). It’s for “sub-time” events inside one time event (with Start/End) dates. I may be complicating things, yes … but I really wanted the visual layout of having all the notes in the same container, with visual links on them.

A starting observation - I’d avoid using ‘prototype’ as the actual $Name of a prototype, it seems to work but I suspect a name collision will bite at some point.

Assuming each COLLECTION notes is linked to by 3 items and all have valid $START and $END values, this code works:

$MyList = (links.inbound."LINK".$Path).sort($START);
$START_1 = $START($MyList.at(0));
$END_1 = $END($MyList.at(0));
$START_2 = $START($MyList.at(1));
$END_2 = $END($MyList.at(1));
$START_3 = $START($MyList.at(2));
$END_3 = $END($MyList.at(2));

I tested in v7.1.0 (using a stamp, FWIW). I suggest you use separate prototypes for collections vs items and add logic to detect if the number of inbound links of type “LINK” is not exactly 3. If you don’t want to use $MyList here, you need to add a List-type attribute named to your choice and change the above code.

Thanks! It works great. Even if the number of links is 1 or 2.

1 Like

Just to share my practical use of this: I’m relating several laws and their approval / effective dates; laws can affect one another (i.e. one revoke another) including several suspension periods. That’s why I wanted this: now I can store in the $KeyAttributes of a law the periods of its suspension (you can see two “suspende” links which do this).

Thanks for the help!


Very nice. :raised_hands:

1 Like

Thanks for sharing. seeing the real-world application of the process worked out above is, I think, really helpful for those starting out with links and actions.