Find all open tasks
How to find all open tasks on an item
There are types of items within Alloy that can have tasks attached to them, e.g. Street Lights can have defects, inspections or jobs associated with them. You can use the Alloy API to find all open tasks.
For more information, see:
Example JavaScript
This example demonstrates how to find all the open tasks for a specific item. In summary:
-
Perform the first AQS query:
Fetch all items of the Task Statuses design and their
itemsTitle
attribute. -
Search the results for the Task Statuses item with an
itemsTitle
that equals Proposed. -
Get the details of the item we're interested in, and then get the value of its
tasksAssignableTasks
attribute (an array ofitemIDs
for any linked Tasks items). -
Perform the second AQS query:
Fetch items of the Tasks interface where their
itemID
matches any of those found in Step 3, AND where theirtaskStatus
attribute equals theitemID
of the "Proposed" Task Status item we got in Step 2.
// load a http request library
const axios = require('axios');
// enter your api key here!
const apiKey = 'e0e3a4ef-5ec8-4e05-ac25-a34adadf4a80';
// the ID of the item that you want to look up open tasks for
const itemId = '5dda8584ca315005f4be5061';
// run the AQS (alloy query syntax) search
// in the first call we are getting all task statuses
axios({
method: 'POST',
url: `https://api.uk.alloyapp.io/api/query`,
headers: { Authorization: `Bearer ${apiKey}` },
// specify the AQS model
data: {
// perform a Query type search
type: 'Query',
properties: {
// search within the Tasks interface
dodiCode: 'designs_taskStatuses',
// search only items in the Live collection
collectionCode: ['Live'],
// return a subset of attributes, alternatively use "All" to get everything
// for Task Statuses we are only interested in the title
attributes: ['attributes_itemsTitle'],
},
},
})
.then((taskStatusResponse) => {
// find the Task Status item with the "Proposed" title
const proposedTaskStatus = taskStatusResponse.data.find(
(taskStatus) =>
taskStatus.attributes.find(
(attribute) =>
attribute.attributeCode === 'attributes_itemsTitle' && attribute.value === 'Proposed',
) !== undefined,
);
// get the item that we want to find tasks for
axios({
method: 'GET',
url: `https://api.uk.alloyapp.io/api/item/${itemId}`,
headers: { Authorization: `Bearer ${apiKey}` },
})
.then((itemResponse) => {
// find its attribute for assigned tasks
const attribute = itemResponse.data.attributes.find(
(attribute) => attribute.attributeCode === 'attributes_tasksAssignableTasks',
);
// get the attribute's value, which is an array of itemIDs of assigned Tasks items.
const taskIds = attribute.value;
// run the AQS (alloy query syntax) search
// in the second call, we're getting all tasks assigned to the item we're interested in
// and filtering them by task status
axios({
method: 'POST',
url: `https://api.uk.alloyapp.io/api/query`,
headers: { Authorization: `Bearer ${apiKey}` },
// specify the AQS model
data: {
// perform a Query type search
type: 'Query',
properties: {
// search within the Tasks interface
dodiCode: 'designInterfaces_tasks',
// search only live items, alternatively you can specify
// an array of collection codes
collectionCode: ['Live'],
},
children: [
{
// the query performs an And check to ensure that
// both children checks are truthful
type: 'And',
children: [
{
// the query performs an equality check to find items by ID
type: 'Equals',
children: [
// the left side of the equality check is the itemID property.
{
type: 'ItemProperty',
properties: {
itemPropertyName: 'itemId',
},
},
// the right side of the equality check is an alloy ID node.
// this will represent one or more item IDs.
{
type: 'AlloyId',
properties: {
// this is an array of item IDs that we want to find.
// we got these from the main item's tasksAssignableTasks attribute.
value: taskIds,
},
},
],
},
{
// the query performs an equality check to check tasks' statuses.
type: 'Equals',
children: [
{
// the left side of the equality check is an attribute.
// the attribute we want to search is Task Status
type: 'Attribute',
properties: {
// specify the code of the attribute we want to search on
// must be an attribute on the dodiCode we chose to search in above
attributeCode: 'attributes_tasksStatus',
},
},
{
// the right side of the equality check is an alloy ID node.
// this will represent an item ID.
type: 'AlloyId',
properties: {
// specify the array of item IDs that we want to match on.
// here, it's the item ID of the "Proposed" Task Status item from earlier.
value: [proposedTaskStatus.itemId],
},
},
],
},
],
},
],
},
})
.then((response) => {
// output the results to the console
console.log(response.data);
})
.catch((error) => {
// output any error data to the console
console.log(error.response.data);
});
})
.catch((error) => {
// output any error data to the console
console.log(error.response.data);
});
})
.catch((error) => {
// output any error data to the console
console.log(error.response.data);
});