Assign a list of tags?

I’ve spent entirely too much time trying to make this work. It seems simple enough. I’ve got an adornment that I want to assign tags to notes when I drag them into it, e.g., tags would be chemistry, oil, and sediments. I’ve tried “$Tags=” and used every syntax I can think of after this to add the tags to the list when moved into the adornment, but with no success. Help would be appreciated.

A Set or List type attribute is a multi-value list ($Tags is Set type) so you can’t just do:

$Tags="Some value";

and expect that to add a new value. To add a new value to $Tags:

$Tags = $Tags + "new value";

For completeness, to remove a value for $Tags:

$Tags = $Tags - "unwanted value";

Note: you can’t use a == test with $Tags to match a single value as Tinderbox tries to match the stored semi-colon delimited list of all values for $Tags that note. You need to use $Tags.contains() or $Tags.icontains() matching a single value and without using regex.

The above observations hold true for any attribute of Set or List type (just change the code accordingly!).

1 Like

OK, I have zero tags on the note(s) at the moment, but you’re saying I still need to add them by using $Tags = $Tags + “new value”; ? Also, are you saying I need to create a list or set of tags somewhere in TB for them to show up as the adornment calls for them; such as I did for my user defined attribute “TopicType.” Sorry to be so ignorant here.

You know, I’m having some fun learning Tinderbox; I just wish I didn’t have to bother everyone with so many questions here.

Well, you can use $Tags = "some value"; for the first value, but otherwise to replaces all the existing values. The $Tags = $Tags + … approach works whether the Set has any values or not so is the correct syntax for adding Set values as you don’t need to vary the code depending on the existing values.

No. Let’s assume your adornment is trying to add the tag ‘overdue’ to the $Tags of a note placed upon it. Thus you’d use (or add to existing) $OnAdd code for the adornment:

$Tags = $Tags + "overdue";

In case you’re using copy paste, check the double quotes in your code are straight (")and not fancy ‘curly’ quotes ( or ) - the later are all different characters, under the hood.

Thanks for all your help Mark, finally it is working. Here is the adornment action that worked for everything I was trying to do:
$OnAdd:$AutoFetch=true;$Prototype=“Ecosystem Prototype”;$TopicType=“Chemistry”;$Color=orange;$Badge=“beaker”;$Tags=$Tags+“Chemistry”;$Tags=$Tags+“Oil”;$Tags=$Tags+“Sediments”

In the space above where you type your entries you can set bold, italic, etc. and the </> button sets any selected text as code … like so. Using the code markup stops the forum software mangling the quotes in your code. So, I read your OnAdd code as follows, placing each discrete expression of a new line just for clarity here (and not needed in the app itself):

$AutoFetch=true;
$Prototype="Ecosystem Prototype";
$TopicType="Chemistry";
$Color=orange;
$Badge="beaker";
$Tags=$Tags+"Chemistry";
$Tags=$Tags+"Oil";
$Tags=$Tags+"Sediments"

The $Color expression only works through legacy support, it is better written as: $Color="orange";

I see you are adding 3 tags in 3 commands. That works but can also be written more succinctly as:

$Tags=$Tags+"Chemistry;Oil;Sediments";

Lists are stored as semi-colon delimited strings - which is how you see them when shown as Key Attributes. In the last example above, Tinderbox with the the single string as actually a list of 3 discrete value to add to $Tags. That said, use which ever form (1 expression or 3) as suits you!

Yes, you read my code correctly. I didn’t notice that the forum changed the straight quotes to curly. I have received so much good help on these forums that I should create a TB file that contains all the responses!

1 Like

In the simple case where your adornment wants to set the tags to a specific value, you can write

 $Tags="Chemistry;Oil;Sentiments";

If you want to preserve all the current tags and add some new ones, you can write

 $Tag=$Tags+"Chemistry;Oil"
1 Like