Merge attributes values between two (or more) notes

Can’t figure this one out. The situation - I have two notes e.g. note1 and note2 each with the same title e.g. Note. note1 has a user attribute “myattribute1” set to some value1. note2 has a user attribute “myattribute2” set to some value2.

My question is how to set update note1 with all the defined user attributes in note2 e.g. effectively merging all user values which are non-null in one of the notes. It’s trivial in this case since I already know the name of the attributes ahead of time. I can use a stamp.

What about the general case in which I need to run through all user attributes for note 1 and note2, check whether they have a value or not, and update one of the notes accordingly.

I’m probably approaching this is the wrong (programming) way but an indication of how to approach the problem would be helpful.

The background is that I have notes in various parts of the document referring to the same concept (satellite parameter in my case) having imported several small spreadsheets of parameters in different locations. I would like to merge/set attributes in a single note defining the concept (and do away with the original).

Not time to run a full test but you’re looking at something like:

$SomeAttribute = values(collect(find($Name==$Name(that)&$Path!=$Path(that)&&IsAlias==false),$SomeAttribute));

N.B. above is not tested. If unfamiliar with the ‘that’ designator, it allows you to use value from the note calling the find().

In the future, you might want to consider whether you want two notes about Telstar, or a single note about Telstar in one place and an alias of that note in another.

I myself would probably use a slightly different approach to the problem than Mark Anderson suggested, though his solution is fine. What I might try:

  1. Define an agent to gather all the notes with the name of this satellite.
  2. The agent’s On Add action sets MyAttribute 1 if the child has a value:
    OnAdd: $MyAttribute1(agent) |= $MyAttribute1;
  3. Similarly, the OnAdd sets $MyAttribute2 of the agent.
  4. Finally, a rule on the agent sets the attributes for each child note.
    $MyAttribute1(children)|=$MyAttribute1;

The notation |= is a conditional assignment; it changes the value of an attribute only if the current value is empty.

1 Like