Sometimes you may want to store values on the device to reuse on the same Screen or in multiple Screens.
For example, say you have a common field in several Form Screens that the user has to select every time - e.g. a project, client or job number. If the user tends to select the same value every time, then you should consider storing this in a Global Value.
Global Values let you specify that a Form field should get its default value from a new key/value store that exists on the device. The functionality works like the name says - its a globally accessible storage across all Screens on a specific device.
For now only the Form screens can leverage this, but we will be introducing Global Values to other screen types soon.
Lets consider an example:
Say you have a screen that has a Project field and a Site field. The Project must be chosen first from the list of available projects, and this then will filter the Site field with the available sites for that project.
- On your Project field, set the "Bind to Global Value" property to be a name of your choice - e.g. "defaultProject".
- On your Site field, set the "Bind to Global Value" property to be a different name of your choice - e.g. "defaultSite".
- Save and set the Form into Test or Published mode.
When an entry for this Form is uploaded, the app will now automatically save the answer for Project into the Global Values key of "defaultProject", and similarly it will do the same for "defaultSite".
The app has effectively created a local dictionary/lookup that looks like:
- defaultProject = "Last project the user selected"
- defaultSite = "Last site the user selected"
When the user next opens your Form, these Global Values will loaded and defaulted into the respective Project and Site fields - thus effectively remembering the last selected values for those two fields.
Similarly you could now also set Project & Site fields in other Forms to bind to the defaultProject & defaultSite Global Values. The same behaviour as above will occur when the user opens these Forms - they will see that Project and Site is preset. This is powerful for cases where you want to have a persistent Project & Site context for the user across multiple Forms.
Using Global Values in a Formula
If you want to refer to a Global Value in a formula, this is also possible - simply use the GLOBALVAL('keyname') formula function.
Note that all Global Values are stored as text, so if you use GLOBALVAL() as an assignment to a Date/Time or Number field, then you will need to convert the value to the correct datatype of the target field. This is done using our TODATE() and TONUMBER() functions respectively.