Building > Reference > tasks.js
Tasks: Definition of tasks shown to app users
This guide explains the parameters available in the Task Schema and important constraints governing the design of tasks.
appliesIf
predicateLet’s synthesize some knowledge about CHT applications to help clarify what is happening within the task system:
All contacts in CHT applications are organised into hierarchies. For more information, read the Contact and User Management Tutorial or schema for contact documents.
All reports in the system are linked to one (and only one) contact. For more information, read App Forms Tutorial or the schema for report documents.
Documents are stored minified (not hydrated). All data that is passed into the tasks system is minified.
Settings which control the documents which are available on the user’s device are an important considerations to remember (eg replication depth or purging) since both tasks can only process docs which are present on the device.
tasks.js
runs on the user’s devices, not in the cloud and not on a server.Every contact and every report on the user’s device is processed by tasks. That said, it is important to remember that this processing is scoped to happen one contact at a time. The code in tasks.js
knows about one contact, but it is not possible to simultaneously know about that contact’s siblings, descendents, ancestors, etc.
With this constraint in mind, we can infer that tasks cannot know the answer to questions like:
The task.js schema includes the noteworthy attribute appliesTo
which has two options: contacts
and reports
. This attribute is important! It changes the algorithm used to process the task, and the meaning of other attributes in the schema.
appliesTo
is important. When you’re ready to write a task, one of the first thing you must decide is the appliesTo
value.The below algorithmic pseudocode explains the relationship between appliesTo
and the attributes appliesIf
and appliesToType
:
algorithm appliesTo is 'contacts'
for contact of contacts:
if contact.type is in task.appliesToType:
if task.appliesIf(contact):
create task events
appliesToType
filters based on the contact document’s contact_type
valueappliesIf
predicate is called once per contact (even if that contact has no reports)appliesIf(c)
is passed information about the contact (c.contact
), and an array of all the contact’s reports (c.reports
)events[].dueDate
defaults to the contact’s creation datealgorithm appliesTo is 'reports'
for contact of contacts:
for report of contact.reports:
if report.form is in task.appliesToType:
if task.appliesIf(contact, report):
create task events
appliesToType
filters based on the report document’s form
valueappliesIf
predicate is called once per reportappliesIf(c, report)
is passed information about the contact (c.contact
), an array of all the contact’s reports (c.reports
), and the current report being iterated on report
events[].dueDate
defaults to the report’s creation dateTasks: Definition of tasks shown to app users
Overview of database document hydration
Schema for database objects
Schema for database objects
Writing and testing a simple task
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.