Tinderbox Forum

I'd like to display the number of aliases of a note in the caption

I have a prototype note called “short story”, and another prototype, “book”. I’ve a master list of short stories, and to show that a story is included in a book (i.e. an anthology) I create an alias for that story and place the alias into the book (as a child). Short stories can appear in multiple books - the anthologies overlap somewhat, and I’d like to know how many times a short story has appeared. This (given the way I’m using aliases) is simply the number of aliases a short story has. I couldn’t find a direct way to get from a note to its aliases. Did I miss something obvious? If there is no direct way, can anyone share their experience/ advice about an efficient way to collect the aliases for a given note?

This display expression on the prototype seems to work (I haven’t tested it in a big doc though… might need some tweaking):

$Name + " (" + (find($ID(original) == $ID(original(that))).count - 1) + ")"

count_aliases.tbx (56.5 KB)

1 Like

Agree. An agent query is designed to return a single match to any note, preferring the original if present and otherwise a single alias. By comparison a query in find() returns all matches - i.e. original and aliases (or all aliases in scope of the query).

To avoid the ‘-1’ construct you can test $IsAlias. Not tested:

$Name + " (" + (find($ID(original) == $ID(original(that)) & $IsAlias).count) + ")"

The original is now out of scope as it evaluates as false for $IsAlias. That said, you get the same result. :grinning:


Thank you @pat and @mwra - I’ve just tried both Pat’s original suggestion and Mark’s variation, both do just what I was after. Seeing the that designator in use was my ah-ha moment.

I’d had a go using find, count, and original and had wondered about checking the hidden internal Alias value to see if it matched the original note’s id.

This is such a friendly and helpful (and responsive) place to ask questions, thank you both again :smiley:

1 Like

Glad you’re sorted. For reference: that.