Tinderbox Forum

AgentQuery : checking if an attribute value is part of a list

I have a list of values for a given attribute (say $Organizations: ACME;BigCo;Optitech;Whatchamacallit)
My “Experts” prototype has an attribute called $LastEmployer which can take on the values of $Organizations.
I want an agent to gather all Experts whose $LastEmployer is either ACME or BigCo.

My initial thought:

  • Make a config note with a user attribute $SectorList=ACME; BigCo
  • Make an agent with an AgentQuery : $Prototype=="Expert"&$SectorList.contains($LastEmployer)

Unfortunately the agent remains desperately empty.

I’m assuming i’m doing something wrong in the Query definition, but I don’t know how to fix it. Any thoughts?

(pretty please: use a back-tick character before after code samples so they render like so, as "code". By comparison the same phrase, as “code”, has here had its quote type changed by the forum software. As curly quotes don’t work in code it means we can’t tell if the error seen is just forum formatting or in your code sample :wink: )

Probably a typo but you’ve spelt ‘BigCo’ 3 different ways: BigCo, BigCO and BicGo. The first can be countered using .contains(), which is case insensitive. The latter wants fixing at source. But, assuming this is just a typo in creating the post…

I think what you’re trying to do is test if the $SectorList of the config note [sic] contains the value(s) held in the $LastEmployer attribute of the note currently being tested. But you query is testing $SectorList of the note being tested. So we’ll give the config note a unique $Name like “sect_config” (i.e. not a ‘normal’ looking one, as it’s only for config purposes). Now the query:

$Prototype=="Expert"&$SectorList("sect_config").contains($LastEmployer)

This works for me. I made 2 test workers one last employed by ACME and the other by Optitech and the query correctly matched only the former.

Actually, I don’t think you need $SectorList. You could have as easily set $Organizations in the ‘sect_config’ note to the desired sub-set of organisation names and used this query:

$Prototype=="Expert"&$Organizations("sect_config").contains($LastEmployer)

One less attribute to worry about. Another appraoch is to simply set the agent’s $Organizations to “ACME;BigCo”. Now you can use this query:

$Prototype=="Expert"&$Organizations(agent).contains($LastEmployer)

This makes it much easier to tweak the string of desired organisations.
(All queries tested)

(Sorry for the confusion. I’ve edited the post for clarity)
Thanks for these suggestions. Of course the $SectorList needs to refer to my config note.
That third suggestion is extremely elegant. I’ll look into it quickly.

In a general sense, I think my brain keeps trying to code with Variables and Constants in one Namespace, rather than being extremely specific about the note where these value live …

1 Like

One simple analogy I use is that of a rolodex or card system. All cards have all boxes (==fields==attributes) even if blank on any given card. From a database perspective, much closer to a flat-file database than a relational database.

Incidentally, when testing the above, I was using suggested values, which you may find useful if not already tried.

thanks for the analogy. you’re right - it may work better.
I was already using suggested values - but i’m looking for a way to construct the list of values programmatically (i.e. get all names of all notes in given container and make that a list of values)

How about Attribute Browser? Seeing all the value categories was art of the original request for that. Or, use Crosstabs but with only one column - you can then export the table data to the clipboard or to file.

Otherwise, use values to make a list, format it with liner breaks, and save a $Text. this can then be exploded, by paragraph into per-value notes. To make a note whose $Text holds a list of $Tags values:

$Text=values("Tags").isort.format("\n");