# Reading from a database

**URL:** <https://forum.getodk.org/t/reading-from-a-database/32817>\
**Category:** Support\
**Created:** [March 15, 2021, 10:30pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817 "2021-03-15T22:30:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MB](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@MB](https://forum.getodk.org/u/MB)\
**Post date:** [March 15, 2021, 10:30pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817/1 "2021-03-15T22:30:52Z")

</div>

I've just started using ODK, but previously used SurveyCTO. I am trying to use the pulldata function to retrieve fields like age, name from the server (in this case gsheet) to display in the form. I guess this is a two part question.

1. Is it even possible to do this? I've read that you don't have bi-directional syncing, but it seems like from some existing threads that people are reading from their database.
2. If you can, how do you do it when writing the form in a CSV?

This is the general function i've used in SurveyCTO, and have tried many different alterations but all have failed.

In the calculation field i've put:  
pulldata('demo\_dataset','age','registration-id', ${uid})

Any help from the community would be much appreciated!

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [March 16, 2021, 8:49am UTC](https://forum.getodk.org/t/reading-from-a-database/32817/2 "2021-03-16T08:49:05Z")

</div>

Hi @MB  
We're glad you're here. When you get a chance, please [introduce yourself on this forum thread](https://forum.getodk.org/t/-/6671). I'd also encourage you to add a real picture as your avatar because it helps build community!

We support functions like pulldata/search which read data from external csv files attached to your form.  
If those csv files are dynamic and you need to update them then you need to upload a new version to your server (ODK Central for example) and redownload in Collect. To make sure it's always updated in Collect you can enable [Exactly match server](https://docs.getodk.org/collect-settings/#blank-form-update-mode)

If you need to know more about those functions:

> **[XLSForm Docs](https://xlsform.org/en/#how-to-pull-data-from-csv)**
>
> This site will help you author XLSForms. XLSForm is a tool used to simplify the creation of forms. XLSForm will convert forms authored in Excel into XForms that can be used with a number of web or mobile platforms.

> **[XLSForm Docs](https://xlsform.org/en/#dynamic-selects-from-pre-loaded-data)**
>
> This site will help you author XLSForms. XLSForm is a tool used to simplify the creation of forms. XLSForm will convert forms authored in Excel into XForms that can be used with a number of web or mobile platforms.

[![](https://getodk.b-cdn.net/uploads/default/original/2X/d/d568a38a6995b4a0a10e9eb847ca0287458a4a49.jpeg "Extract and access external data using "Pulldata" in XLSForm, Kobo Toolbox, and ODK") ](https://www.youtube.com/watch?v=-Hi_K1rWxCo)

[![](https://getodk.b-cdn.net/uploads/default/original/3X/a/4/a430f34f451c455fb7b4a3efa124abdbdea8c64e.jpeg "How to Use the Search Function in XLSForm, ODK, and KoboToolbox - when you have thousands of choices") ](https://www.youtube.com/watch?v=eEXa8GK4yE4)

---

<div class="post-metadata">

**Author:** ![MB](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@MB](https://forum.getodk.org/u/MB)\
**Post date:** [March 16, 2021, 6:03pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817/3 "2021-03-16T18:03:33Z")

</div>

Thank you @Grzesiek2010, really helpful. And helped me see that i'm structuring the function correctly, but I'm still not able to pull the data. A few additional questions:

1. Could it be that this only works if its hitting a csv file name and therefore since I am using google sheets url that it will not work?

2. I have a repeat group where I am extracting data from an android intent response. I am using count-selected to count the number of returns we get and then in the repeat group, I am using indexed-repeat to extract the data. Are these the right functions to use?

Apologies for what are likely rudimentary questions. I have run through so many iterations and although my csv is validated when i convert to xform, when i run through the form the pulldata retrieves blanks. I'm effectively trying to diagnose at what point in the form that I am doing something incorrectly.

Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [March 16, 2021, 6:52pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817/4 "2021-03-16T18:52:08Z")

</div>

The best option would be to share your form here if it's possible so that we can see and test it. Could you do that?

---

<div class="post-metadata">

**Author:** ![MB](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@MB](https://forum.getodk.org/u/MB)\
**Post date:** [March 16, 2021, 9:48pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817/5 "2021-03-16T21:48:13Z")

</div>

Hi @Grzesiek2010 happy to do that. Slight caveat is that this form is integrating into a biometric system, and in order to test you would need to be set up with a project for them and have their app. But I think just seeing the form should be enough to identify where i've gone wrong.

The issue (I'm nearly certain) sits between rows 26-40, which is where I am extracting the delimited list of results being returned to the app and then displaying the results.  
The image on the left is the page being displayed after the callback from the biometric app, which is correct. But then the image on the right is where I'm trying to calculate and extract the corresponding names and ages of the GUIDs that sit in the database, but i'm getting the results you see there.

Thank you so much for your help.

 ![Results Page](https://getodk.b-cdn.net/uploads/default/original/2X/5/5007b3c51a1537ee12179d561fcf03fb9f6e3cda.jpeg) ![Results List](https://getodk.b-cdn.net/uploads/default/original/2X/0/0de563a5b6f8991cda4a038204190bfe3a580171.jpeg)

[ODK Exploration copy.xlsx](https://forum.getodk.org/uploads/short-url/A9pHONymZg5FHeVGHsHx2BjOXlS.xlsx) (28.9 KB)

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [March 16, 2021, 10:21pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817/6 "2021-03-16T22:21:55Z")

</div>

Ah ok so as I thought you are trying to use `pulldata` with an online sheet. That's not possible. You need to download such a file (it must be a csv file) and upload it as a media file (like image/audio/video files for example).  
Did you see anything (documentation or something) that would indicate it's supported?

---

<div class="post-metadata">

**Author:** ![MB](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@MB](https://forum.getodk.org/u/MB)\
**Post date:** [March 22, 2021, 3:04pm UTC](https://forum.getodk.org/t/reading-from-a-database/32817/7 "2021-03-22T15:04:47Z")

</div>

Ah ok, yeah that was my hunch too. I struggled to find any documentation that mentioned the `pulldata` function. So best bet would be for me to buy ODK Cloud and set up a server, or to set up my own, I suppose?

Also, would you kindly check the Calculation fields for rows 26-40 as well? I've made quite a few changes to these fields and want to make sure I am leveraging the right functions to recursively loop through the results and to ultimately have them display correctly.

Looks like we're nearly there! Thank you!

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [March 24, 2021, 11:52am UTC](https://forum.getodk.org/t/reading-from-a-database/32817/8 "2021-03-24T11:52:06Z")

</div>

> [@MB](#):
>
> So best bet would be for me to buy ODK Cloud and set up a server, or to set up my own, I suppose?

It's always a better and easier option to use ODK Cloud.

When it comes to your calculations (rows 27-29) you don't need indexed-repeat() functions there because you refer questions that are in a regular group so there is just one instance for for every question (`odk-registration-id`, `odk-guids` etc). Indexed-repeat() is used when you refer questions that are in a repeat-group.  
From row 35 it makes sense because there you refer `concatinfo` which is in a repeat group indeed.

---

<div class="post-metadata">

**Author:** ![jjjdec](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/jjjdec/32/24969_2.png) [@jjjdec](https://forum.getodk.org/u/jjjdec)\
**Post date:** [April 9, 2024, 10:16am UTC](https://forum.getodk.org/t/reading-from-a-database/32817/9 "2024-04-09T10:16:25Z")

</div>

Hello, i know this is an old thread but i wanted to ask the same question. Has there been any updates on pulldata using an online sheet or this is still not possible?

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [April 10, 2024, 12:06am UTC](https://forum.getodk.org/t/reading-from-a-database/32817/10 "2024-04-10T00:06:23Z")

</div>

It's not possible to directly look up values from an online source. Can you share more about your use case? What kind of data are you trying to look up? Is the dataset you want to use public?

You can use attached CSV files like this thread describes ([Central documentation](https://docs.getodk.org/central-forms/#forms-with-attachments)).

You can also attach more dynamic lists of items which we call Entity Lists ([Central documentation](https://docs.getodk.org/central-entities/)). You can create and update Entities through form submissions and also by writing your own program that uses [the API](https://docs.getodk.org/central-api-dataset-management/).

You can find an example script that creates many entities from a CSV [here](https://forum.getodk.org/t/datasets-in-central-are-now-entity-lists-please-help-translate/42893/4). You could use this to periodically synchronize values from some external data source in Central (if values in your data source can be updated, you would also need to use [the update endpoint](https://docs.getodk.org/central-api-entity-management/#updating-an-entity)). That list would then go out to all of your data collectors and their forms could look up values in it.
