# Auto-populate repeating form fields using a query string

**URL:** <https://forum.getodk.org/t/auto-populate-repeating-form-fields-using-a-query-string/29976>\
**Category:** Support\
**Tags:** enketo\
**Created:** [September 16, 2020, 7:45am UTC](https://forum.getodk.org/t/auto-populate-repeating-form-fields-using-a-query-string/29976 "2020-09-16T07:45:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anant](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/anant/32/6655_2.png) [@Anant](https://forum.getodk.org/u/Anant)\
**Post date:** [September 16, 2020, 7:45am UTC](https://forum.getodk.org/t/auto-populate-repeating-form-fields-using-a-query-string/29976/1 "2020-09-16T07:45:09Z")

</div>

How to Auto populate repeating form fields/grids using query string in Enketo form.

We are using below versions  
ODK Version : 2.0.5  
Enketo Version : 2.1.1

Tried building query string , but able to populate only first row of repeating table/grid  
How can i populate multiple rows using query string

Query String :  
https://{domain-name}/x/ir5M7ZUS/?&d[/data/group1/cancer\_repeat/others]=1&d[/data/group1/cancer\_repeat/report]=1&d[/data/group1/cancer\_repeat/refer]=1&d[/data/group1/cancer\_repeat/mgmt]=1

PFA excel form which is used to generate repeat grid type form

[repeat\_block.xlsx](https://forum.getodk.org/uploads/short-url/hFEOO4kFpR0I8Clrp9b1hHWDfOf.xlsx) (11.2 KB)

PFB form screenshot, we were able to populate 1 row , but how could we populate multiple rows using query string.

 ![repeat form](https://getodk.b-cdn.net/uploads/default/original/2X/6/69b810a593c437321b8bfac7ec74584d3102267f.jpeg)

@martijnr can you please help us out on this

---

<div class="post-metadata">

**Author:** ![martijnr](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/martijnr/32/1614_2.png) [@martijnr](https://forum.getodk.org/u/martijnr)\
**Post date:** [September 16, 2020, 4:22pm UTC](https://forum.getodk.org/t/auto-populate-repeating-form-fields-using-a-query-string/29976/2 "2020-09-16T16:22:25Z")

</div>

Hi @Anant,

The questions are referred to using XPath. In XPath 'positions' are 1-based so the first repeat is `/data/group1/cancer_repeat[1]` (or as you used, since it will get the first automatically) and the second is `/data/group1/cancer_repeat[2]`. Please make sure to use Enketo's API as it will take care of encoding the query parameters.

I hope this helps. This is not a heavily-used feature, so you may very well find bugs. If you do, please report them here: [https://github.com/enketo/enketo-express](https://github.com/enketo/enketo-express). I'm not actually sure if the non-first repeat instances are created automatically. I don't think we've tested this...

---

<div class="post-metadata">

**Author:** ![Anant](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/anant/32/6655_2.png) [@Anant](https://forum.getodk.org/u/Anant)\
**Post date:** [September 17, 2020, 3:38am UTC](https://forum.getodk.org/t/auto-populate-repeating-form-fields-using-a-query-string/29976/3 "2020-09-17T03:38:12Z")

</div>

Hi @martijnr,

Thanks for quick reply.

As per your suggestion above , I tried.

https://{domain-name}/x/ir5M7ZUS/?&d[/data/group1/cancer\_repeat[1]/others]=1&d[/data/group1/cancer\_repeat[1]/report]=1&d[/data/group1/cancer\_repeat[1]/refer]=1&d[/data/group1/cancer\_repeat[1]/mgmt]=1&d[/data/group1/cancer\_repeat[2]/others]=1&d[/data/group1/cancer\_repeat[2]/report]=1&d[/data/group1/cancer\_repeat[2]/refer]=1&d[/data/group1/cancer\_repeat[2]/mgmt]=1

But its populating 1 row only.  
PFB screenshot.

 ![repeat form](https://getodk.b-cdn.net/uploads/default/original/2X/6/69b810a593c437321b8bfac7ec74584d3102267f.jpeg)

Kindly let me know if am doing anything wrong with the query.

Thanks and Regards,  
Anant

---

<div class="post-metadata">

**Author:** ![martijnr](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/martijnr/32/1614_2.png) [@martijnr](https://forum.getodk.org/u/martijnr)\
**Post date:** [September 21, 2020, 5:21pm UTC](https://forum.getodk.org/t/auto-populate-repeating-form-fields-using-a-query-string/29976/4 "2020-09-21T17:21:21Z")

</div>

Hi @Anant,

If you are using the API instead of the handcrafted unencoded URL you posted, you seem to be doing this right. So there is likely a bug in this feature wrt non-first repeat instances. If you have time to create a nice reproducible issue on GitHub, that would be much appreciated.

Cheers,
