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.
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:
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:
Note: If you are calculating an Initial Answer based on another field's value (like using LOOKUP), the initial answer field will need to become active after the associated field is answered. Use the Active- Only when rule for this.
Duplicating Answers in a Repeat Group
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.
Summarise Answers from a Repeat Group
When using a Repeat Group, you may want to show a summary of your repeat group items later in the form. For example, you may want to show a summary of product names that were added to each repeat group item.
First add an additional Free Text Field to your Repeat Group (we'e named this: Summary) and edit the initial answer expression:
IF(COUNT(.Group) > 1,CONCATENATE(.Group[COUNT(.Group) - 2]/Summary," + ",Product_Name),Product_Name)
Note: In this example an
+ will be added between each item in the Summary.
The Summary field should be set up to only become active when Product Name has a value.
Now add another Free Text Field outside of the Repeat Group (we've named this: Summary (+ between each value)) with the following initial answer expression:
Group[COUNT(Group) - 1]/Summary
Then add a Yes/No field (Generate Summary) and set the Summary (+ between each value) to only become active if "Yes" is selected.
After selecting "Yes" for Generate Summary, the Summary (+ between each value) field will become active and show the summary of the Product Names.
Watch this space for future examples.
Other Useful Articles:
If you have any questions or comments feel free to send us a message at email@example.com.