Trouble getting an agent to search notes using $Name of parent

I’m having trouble getting an agent to search notes for the name of a company in other notes.

The way I’ve structured this agent action is for the agent to be a child of a company note. The agent should get the company name of its parent company note and use this name to search episode notes. The goal is to find all those episodes that contain the name of the company in the $CompaniesInvolved attribute, which is a set. I’ve checked to be sure the spelling is correct.

Companies are contained in “Resources/Entity/Companies” and episodes are contained in a separate “Episodes” note.

If I explicitly include the name of the company, for example,

$Prototype=="pEpisode" & $CompaniesInvolved.contains("Boston Manufacturing Company");

it works as intended and the agent then contains the aliases of all the notes with the name of “Boston Manufacturing Company” in the $CompaniesInvolved attribute. The agent’s parent note’s name is "Boston Manufacturing Company”.

I’d like to automate this so that the agent gets the name to search for from the name of its parent note. Then I can use the agent in each the company note to find out which episode notes that company is involved in. Note, there may be more than one company in the $CompaniesInvolved set attribute.

I’ve tried the following but it doesn’t work at all.

$Prototype=="pEpisode" & $CompaniesInvolved.contains($Name(parent))

What have I done wrong about structuring this query? Any help would be appreciated.

In another post I’ll explain the approach I’m using to study the interrelationship between various New England manufacturing companies during the 19th century.

1 Like

It looks like you are using curly quotes ’ “ '. They should be a straight quotes.

You can use the inspector to write your action code. If you’re using $Text to write your action code, as I often do, then add $SmartQuotes to the displayed attributes and set it to false, or you can do this with the Quickstamp in the inspector.

My initial thought was as above, but as I’ve admin access, I checked your posts source, and the curly quotes are an artefact of how the forum software works. Whilst under the hood, I added some markup to preserve the code from this extra change - but I’ve not otherwise altered the post!

Tip. If typing literal code there are two ways to mark it so.

  1. For a single line of code or code within text, put a back-tick ` before and after the code. You can do the sale to a selection of text using the </> button above the post draft input box (4th from left). Do not use this method for multi-line code samples.

  2. For one or more lines of code put three back-ticks ``` (and nothing else) on a line before and after the code. If you don’t want the code colouring (which doesn’t actually use Tinderbox syntax) simply add a space and the word ‘text’ after the back-ticks on the line above the code. (I can’t show it as the forum s/w get confused!).

I’ll respond on the above in a separate post.

The $Name(parent) in the query is getting the $Name of parent of the note being tested by the query. But, you want the name of the parent of the agent. We do that like so:

$Prototype=="pEpisode" & $CompaniesInvolved.contains($Name(parent(agent)))

Now every note is testing against the same string - the $Name of the agent’s parent container.

Here is a small TBX as proof-of-concept: Agent-query-fix1.tbx (184.6 KB)

3 Likes

Thank you Mark A.
That solution works quite well. Also, because the code is generic I can easily copy paste agents and add them to the company container, or other type of container such as a person, without any modification. I would never have thought that simply adding another redirection with the name “agent” would be needed or worked. To be sure it worked I tried it on another company and it’s episodes, works fine.

2 Likes