Example 4 - Parameters and AQS Join
This example demonstrates how to build the following query in the AQS Builder:
Fetch all inspections assigned to a particular team
In full detail:
Fetch items of the Inspections interface with a Link attribute that references a Teams item, which has a Team Name attribute equal to some text
We'll use a TeamName parameter as a placeholder for "some text".
Configure the root node
-
Select the root node and set the following properties:
- AQS Type - AQS Join
- Design or interface - Inspections
- Collection - Live
- Attributes - Title, Subtitle, Team Name
Note that we're using AQS Join for this query because we're not only fetching attribute data from the queried Inspections items, but also the Teams items they link to (to get the value of their Team Name attribute).
When selecting attributes in the Pathfinder, follow the Team Link attribute to the Teams design, where you can then select its Team Name attribute.
Add a parameter
- Select and populate the fields like so:
To change how the parameter looks in Alloy, supply a Display Name. It'll still be called Name in the underlying AQS code.
Add a comparison node
- Select and choose the Equals node type from the list.
Fill the left segment
- Select on the left and choose the Attribute node type from the list. The node will default to the first relevant attribute in the design/interface being queried.
- Select and use the Pathfinder to navigate to the Teams design and select its Team Name attribute (see step 1).
The indicates that the selected attribute belongs to another design/interface than the one being queried.
Fill the right segment
- Select on the right and choose the Text node type. Select Parameter and choose TeamName.
Finish
- Select Done (bottom-left) to finish.
See JSON code
{
"type": "Join",
"properties": {
"attributes": ["attributes_itemsTitle", "attributes_itemsSubtitle"],
"collectionCode": "Live",
"dodiCode": "designInterfaces_inspections",
"joinAttributes": ["root.attributes_tasksTeam.attributes_teamsTeamName"],
"parameters": [
{
"name": "TeamName",
"type": "String"
}
]
},
"children": [
{
"type": "Equals",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_teamsTeamName",
"path": "root.attributes_tasksTeam"
}
},
{
"type": "String",
"properties": {
"parameterName": "TeamName"
}
}
]
}
]
}
Populating the parameter
When a user runs the query, they'll be prompted to supply a value for the parameter.
As shown above, it's possible to add multiple values for the parameter. The query will fetch any Jobs item linked to a Teams with an applicable Team Name value.