Setting a dynamic value as an initial answer for a question is possible by setting it's expression. Previously, only static values could be set for questions other than a calculated question. Below, you'll find an example to help you get started building expressions for initial answers.
If you'd like access to this feature, please contact firstname.lastname@example.org.
Please note, this feature is not fully supported on Android yet.
First, open your form in the designer and locate the question you'd like to set the initial answer for. Click the question and check the "Show Advanced Settings" option.
You'll see the Initial Answer text box for static values and the option to set an expression just below.
Click "set expression".
If you're unfamiliar with our available functions and other calculated question capabilities, have a look at this article before reading further.
To set the initial answer to the current date present on the device, use the expression pictured below.
See the article link above for information on how this expression is constructed. When the form is opened in the app, it'll look like this:
To change the initial answer, click the "x" to the right of the answer.
Note: Your initial answer expression must return a value in the format required by the field type. For example, if you are using a LOOKUP to fetch a Date, Time, or Date-Time value, the data must be formatted correctly in your spreadsheet:
Date should be formatted as follows:
Time should be formatted as follows:
hh-mm-ss Example: 15:06:00
Date-Time should be formatted as follows:
Duplicating Answers in a Repeat Group
Note, this is supported on iOS only at this time.
When using a Repeat Group, there may be instances where you’d like the initial answer to populate with the answer from the previous entry in the group. This is useful if you are collecting information about multiple items that all share the same (or very similar) details. This can be accomplished by using the following initial answer expression format:
.Your_Repeat_Group[COUNT(.Your_Repeat_Group) - 2]/Some_Question
For example, if you had a Repeat Group called “Buildings” and fields within the Repeat Group called “Building Name”, “Year Built”, and “Square Feet”, your form builder would look like this:
In this example, you would set the Initial Answer Expression on “Building Name” as follows:
Use the same initial answer expression for each of the following questions within the repeat group, updating only the field name. So the initial answer expression on the field "Year Built" would look like this:
.Buildings[COUNT(.Buildings) - 2]/Year_Built
Now, once the user completes an entry in the repeat group, all the data will carry over into the following entry as the initial answers.
Duplicating Answers inside Subforms within a Repeat Group
If the field you would like repeated is inside a Subform in the Repeat Group, you'll need to add the name of the subform to the expression too. For example: "/Subform".
..Group[COUNT(..Group) - 2]/Subform/Free_Text_Question
Also, note the additional dot in front of the "Group" names for each level.
If your form has 3 levels, your expression will need to look as follows:
...Group[COUNT(...Group) - 2]/Subform1/Subform2/Free_Text_Question
Auto-Number Your Repeat Group Entries
When using a Repeat Group, there may be instances where you’d like to count your entries as they are added, automatically giving each entry a number (i.e. Entry 1, Entry 2, Entry 3, etc). This can be useful for identifying specific entries within a Repeat Group. You will use the following format for your Initial Answer Expression:
SUM(.Group_Name[COUNT(.Group_Name) - 2]/Integer_Field_Name,1)
Start by adding an integer field to your repeat group, and label it whatever you'd like. in this example, it is called "Entry Number"
Next add your Initial Answer Expression to your integer question. In this example the expression would look like this:
Now as you add Repeat Group entries in your mobile app, you will see that each entry is automatically numbered.
Watch this space for future examples.
Other Useful Articles:
- Calculated Question Expressions
- Form Field Accessibility Settings
- Repeat Groups
- PDF/Word Template Date Formatting Options
If you have any questions or comments feel free to send us a message at email@example.com.