You can pre-populate a form with data from a CSV file. This is useful in many scenarios such as baseline data that you want to include in a follow-up form.
CSV file validation
Additional validation rules are applied to both the header and data rows of a CSV file resource to ensure issues do not occur during data collection.
- Header values can only contain letters, numbers or underscores and must begin with a letter. No spaces or other special characters are allowed. The length of a header value cannot exceed 100 characters.
- Data values can contain any characters except for double quotes " or backticks `.
Here's an example of a valid CSV file:
header_1 | header_2 | header_3 |
---|---|---|
Some data | Example email@address.com | $240 |
Valid data can include single quotes (') | Dates allowed 1987-10-20 | $303 |
Step 1: Get your data into a CSV file
Set up your CSV with the data that will be referenced in your form, including the name/PID that will be used to match with the field in the form. The easiest way to generate a CSV is to create a spreadsheet using Microsoft Excel or Google Sheets and then save as a CSV file.
Hint: Dates should always be in the format yyyy-mm-dd
Here's an example of a CSV file:
PID | date_of_birth | gender | registration_date | Occupation |
1231 | 1987-10-20 | M | 2020-01-09 | Teacher |
1115 | 1988-03-19 | F | 2019-08-15 | Nurse |
Step 2: Upload the CSV file to your project resource library
Once you have saved your data to a CSV file, you can upload it to your project resource library. Uploading resources to your library is covered in more detail in the article Embedding media in your form.
Step 3: Pull the data into your form
1. Add a field to enter the name/patient ID for example. This will be matched with the corresponding data in the CSV file.
2. Add a calculation field with the =pulldata() function in the formula to retrieve the data from the CSV file - e.g. =pulldata(@TestFile.csv, "Occupation", "PID", $PID)
- The first parameter is used to reference the CSV file using the '@' sign.
- The second parameter refers to the column that contains the data you wish to populate.
- The third parameter is used to locate the column you wish to match.
- And the last parameter is the value you want to match on. You can reference another field by using the '$' sign.
Data from the pulldata() function will be included with the form submission data in the analytics grid.
Step 4: Reference the data in your form (optional step)
Once the data is loaded using the pulldata() function, you can reference the field (with the '$'sign) in another field's label or use as skip logic / validation conditions, just as you would reference any other field.
Tip: To see pulldata() in action, use the 'Preview' button on the far right in your top toolbar to view the form in mobile or web view.