Adding field automation to forms
Table of Contents
In GIS Cloud, forms that you use to structure your data collection and data editing are based on the JSON format. The JSON for a particular form can be accessed in the Forms Manager by clicking on JSON View (as opposed to the Designer View, which enables you to edit the form through the UI).
You can use the JSON to add functionality to the form (such as adding autocomplete fields), quickly add many items to select lists/radio buttons/checkboxes, or easily copy forms between different accounts.
JSON can also enable you to populate fields with specific values automatically! This feature can be used to automatically fill fields with certain values (this can be a predefined value, the value from another form field, or today’s date) if certain criteria is met – specifically, if the field we’re referring to in the automation rule has a specific value that we defined.
The JSON Structure for Automation
So, how does this work? Let’s examine the form field example below to learn about the elements we need to set an automation.
{
"type": "text",
"uuid": "4fe0c214-ae76-4228-b7ee-106dbde4a8e8",
"name": "Form field name",
"description": "",
"automationRules": [
{
"condition": {
"all": [
{
"field": "593fca11-6f65-4ec8-bd5e-9c0196e073ed",
"value": "1"
},
{
"field": "68800811-b18d-463f-acd0-071a9458d4ac",
"value": "2"
}
]
},
"action": {
"type": "predefined",
"value": "3"
}
}
]
}
Automation Rules
automationRules
is an array that contains a list of all automation rules for a particular form field. Each rule consists of a condition (condition
), and an action (action
). If the condition is met, the action will be completed.
If we have more than one rule, then the first rule that has all conditions met will determine the action. Keep this in mind, and order the rules in this list accordingly.
Condition
An automation rule can have multiple conditions (a condition can, for example, be: “field_A must have a value of 5”, or “field_B”). The condition
object can have the following keys: all | any | one | none
.
This means that we can signify whether we want all the conditions, any of the conditions, one of the conditions or none of the conditions to be met to complete the action. In the example below we added two conditions and both need to be met in order for the action to be completed.
"condition": {
"all": [
{
"field": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"value": "100"
},
{
"field": "ccc6a7eb-4bd0-4ad7-a900-e3023ca8987d",
"value": "Done"
}
]
}
Action
There are three actions we can use in the type value of the action object: predefined | field_value | today_date
For all actions, we need to consider the type of field we’re populating — i.e., if we’re setting the automation on a numeric field, we can only populate the field with a numeric value (real, integer).
Let’s take a look at each action option separately:
Predefined values
"action": {
"type": "predefined",
"value": "3"
}
We can define the automation to populate the automated field with a predefined value if the condition we set is met. In the example above, if our condition is met, the field will be populated with the value 3.
Example – The value of the Inspection status field changes to Done if the value for the Completion % field is 100
{
"name": "Automation example - Predefined value",
"title": "Automation example - Predefined value",
"description": "Value of the Inspection status field changes to Done if the value for the Completion % field is 100",
"items": [
{
"type": "numeric",
"uuid": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"name": "completion_pct",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Completion %",
"description": ""
},
{
"type": "select",
"uuid": "ccc6a7eb-4bd0-4ad7-a900-e3023ca8987d",
"name": "inspection_status",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Inspection Status",
"description": "",
"options": [
{
"title": "Not started",
"value": "Not started"
},
{
"title": "In progress",
"value": "In progress"
},
{
"title": "Done",
"value": "Done"
}
],
"automationRules": [
{
"condition": {
"all": [
{
"field": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"value": "100"
}
]
},
"action": {
"type": "predefined",
"value": "Done"
}
}
]
}
]
}
Note how in the example above, the condition refers to the UUID of the completion_pct field.
We can use this on items such as checkboxes as well, in which case, we can use the action to check multiple values by adding a comma, for example: “value”: “1,3”
Field values
"action": {
"type": "field_value",
"sourceField": "<uuid from the field whose value we’re copying>"
}
We can define the automation to populate the automated field with the value of another field if the condition we set is met. This is done by referencing the UUID from the field whose value we’re copying into the automated field.
Example – The value of the Inspection status field changes to Done if the value for the Completion % field is 100
{
"name": "Automation example - Value from other field",
"title": "Automation example - Value from other field",
"description": "Value of the Updated asset field changes to the value of the Asset ID field if the value for the Completion % field is 100 OR if the Inspection status is set to Done",
"items": [
{
"type": "text",
"uuid": "0d51c5d3-44b4-48f3-adeb-ff30647beb30",
"name": "asset_id",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Asset ID",
"description": ""
},
{
"type": "numeric",
"uuid": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"name": "completion_pct",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Completion %",
"description": ""
},
{
"type": "select",
"uuid": "ccc6a7eb-4bd0-4ad7-a900-e3023ca8987d",
"name": "inspection_status",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Inspection Status",
"description": "",
"options": [
{
"title": "Not started",
"value": "Not started"
},
{
"title": "In progress",
"value": "In progress"
},
{
"title": "Done",
"value": "Done"
}
]
},
{
"type": "text",
"uuid": "3ccd55e7-ba90-497c-86a4-4bd71ae29a79",
"name": "updated_asset",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Updated asset",
"description": "",
"automationRules": [
{
"condition": {
"any": [
{
"field": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"value": "100"
},
{
"field": "ccc6a7eb-4bd0-4ad7-a900-e3023ca8987d",
"value": "Done"
}
]
},
"action": {
"type": "field_value",
"sourceField": "0d51c5d3-44b4-48f3-adeb-ff30647beb30"
}
}
]
}
]
}
Today
"action": {
"type": "today_date"
}
We can define the automation to populate the automated field with today’s date if the condition we set is met.
This action must only be defined when the automation is set to a datetime form field.
Example – The value of the Inspection date field changes to today’s date if the value for the Completion % field is 100
{
"name": "Automation example - Today's date",
"title": "Automation example - Today's date",
"description": "Value of the Inspection completed on field changes to today's date if the value for the Completion % field is 100",
"items": [
{
"type": "numeric",
"uuid": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"name": "completion_pct",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Completion %",
"description": ""
},
{
"type": "datetime",
"uuid": "ccc6a7eb-4bd0-4ad7-a900-e3023ca8987d",
"name": "inspection_date",
"persistent": false,
"required": false,
"readOnly": false,
"title": "Inspection completed on",
"description": "",
"mode": "datetime",
"automationRules": [
{
"condition": {
"all": [
{
"field": "5b2f9bd1-2ad1-4120-b939-7a562ad82800",
"value": "100"
}
]
},
"action": {
"type": "today_date"
}
}
]
}
]
}
General guidelines
Form field automation follows the general guidelines listed below:
- Automation rules will work when using forms both in the Mobile Data Collection app and in the web apps (Map Editor)
- Note that you need to have the MDC version 9.5.7 or above
- The conditions that you set for a particular field can only reference fields that come before this field in the form (in the same way that Dependencies are set).
- You can set multiple rules for one field, as well as multiple conditions for one rule.
- If we have more than one rule, then the first rule that has all conditions met will determine the action. Keep this in mind, and order the rules in this list accordingly.
- Once a field value is changed based on an automation rule you set, you can still change the value for that field manually. If the field that you set as the condition is then changed again, and this change is a condition for automation, this will also trigger the automated field to change again.
- Automation can be set on the following form field types: text, number, datetime, select, radio, checkbox, QR/barcode. Learn more about all field types here.
- Keep this in mind when setting the automation conditions and rules – for example, you cannot set the automation to fill a number type field with the value “ABC” because the number field doesn’t support text (string).
- You cannot set automations on fields with the Read-only, Persistent, or Default value options enabled. Learn more about all form field options here.
- Your JSON needs to stay valid – ie. keep track of the brackets, commas, etc.