[sorry for delayed reply, hit by a couple of long calls, but here’s my worked solution for you]
OK, this took some doing as your requirement for an agent to list the references took some doing. this is because within an agent query, there is a limit to the nested complexity of the query you can answer.
To match your need all these must be true:
- the note is of prototype ‘Reference’
- the reference is used by a topic (i.e. linked by a ‘Reference’-type link)
- the linked topic must reside under container ‘Oral Exams Semester XYZ’
This is because not all references are necessarily used and not all topics using references are necessarily part of the current semester.
How do we do this?
- I added a new user Set-type attribute ‘MySetA’ so that I could replicate $ID data stored in $MySet ad used for production work with $Name data stored in $MySetA.
- I added a prototype ‘pTopic’ so I could easily apply code to all topics
The ‘pTopic’ has this rule:
if($IsAlias==false){
// collect IDs of all refs linking to this note
$MySet = links.inbound."Reference".$ID;
// collect titles of all refs linking to this note
$MySetA = links.inbound."Reference".$Name;
};
Only if the note is an original (i.e. not an alias) does the main rule code run. Why? Bear in mind we define the topic once and then place an alias of it under each student. The result is each topic knows which references apply to it. Here the $MySetA data is only to help you understand the process
Next we make an agent which I have called ‘@Relevant Topics’ which has this query:
$Name(grandparent)==$MyString(agent) & $Prototype=="pTopic"
Where the agent’s $MyString is the name of the exam semester we wish to test, e.g. “Oral Exams Semester ABC
” . The agent’s rule is:
// get the IDs of references used by current topics
$MySet=collect(children,$MySet);
// get the Names of references used by current topics
$MySetA=collect(children,$MySetA);
// set explanatory text for the agent
$Text = "For test/check purposes, the following "+$MySet.count+" references should be found by the agent '@References In Use':\n\n"+$MySetA.format("\n\n");
The only bit we need is the $MySet data, the rest is to help understand the process. So by changing $MyString in the agent we store the $IDs of the references in use. The resulting $Text of this first agent then looks like this:
Now we can use a second agent ‘@References In Use’ to find only the relevant references and we do it with this query:
$Prototype=="Reference"&$MySet("@Relevant Topics").contains($ID(original))
So we start by getting all Reference-type notes and then we only continue to match them if their original note’s $ID is in the list of IDs stored in the $MySet of the first agent.
In many cases, a single agent would suffice, but your scenario has too many contingent factors to resolve in a single query. For what it is worth, just listing the names of the references in a note’s $Text is significantly less work and can be done a number of ways, but that wasn’t the starting scenario.
Here’s more of the overall setup:
and here is the test file: RefListTest1.tbx (422.1 KB)