# Auto-fill consecutively between groups?

**URL:** <https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031>\
**Category:** Support\
**Created:** [March 17, 2014, 11:18pm UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031 "2014-03-17T23:18:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![havey\_dewlett](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@havey\_dewlett](https://forum.getodk.org/u/havey_dewlett)\
**Post date:** [March 17, 2014, 11:18pm UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031/1 "2014-03-17T23:18:24Z")

</div>

Basically I'm trying to automatically fill fields consecutively between  
groups.

Example:  
Survey 1  
Basic survey information (date, location, surveyor)  
Plant data (start groups)  
Plant 1 (group 1)  
Plant type: A, B, or C\* (manually select)\*  
Seed sample #: _3456_\* (auto fill)\*  
Plant 2 (group 2)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _3457_\* (auto fill)\*  
Plant 3 (group 3)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _3458_\* (auto fill)\*  
Plant 4 (group 4)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _1234_ \* (manually override, samples were not in  
order)\*  
Plant 5 (group 5)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _1235_\* (auto fill)\*  
Plant 6 (group 6)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _1236_\* (auto fill)\*  
End survey

If anyone knows if this is possible and/or can simply point me in the right  
direction, that'd be a huge help!  
Thanks!

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [March 18, 2014, 3:21am UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031/2 "2014-03-18T03:21:57Z")

</div>

position() will tell you which repeat you are in. Take that number, do  
whatever math or string manipulation (e.g., concat()) to get the  
number you want.

Yaw

> **···**
>
> -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.
> 
> On Mon, Mar 17, 2014 at 4:18 PM, havey dewlett [hewlett.david@gmail.com](mailto:hewlett.david@gmail.com) wrote:
> 
> > Basically I'm trying to automatically fill fields consecutively between  
> > groups.
> > 
> > Example:  
> > Survey 1  
> > Basic survey information (date, location, surveyor)  
> > Plant data (start groups)  
> > Plant 1 (group 1)  
> > Plant type: A, B, or C (manually select)  
> > Seed sample #: 3456 (auto fill)  
> > Plant 2 (group 2)  
> > Plant type: A, B, or C (manually select)  
> > Seed sample #: 3457 (auto fill)  
> > Plant 3 (group 3)  
> > Plant type: A, B, or C (manually select)  
> > Seed sample #: 3458 (auto fill)  
> > Plant 4 (group 4)  
> > Plant type: A, B, or C (manually select)  
> > Seed sample #: 1234 (manually override, samples were not in order)  
> > Plant 5 (group 5)  
> > Plant type: A, B, or C (manually select)  
> > Seed sample #: 1235 (auto fill)  
> > Plant 6 (group 6)  
> > Plant type: A, B, or C (manually select)  
> > Seed sample #: 1236 (auto fill)  
> > End survey
> > 
> > If anyone knows if this is possible and/or can simply point me in the right  
> > direction, that'd be a huge help!  
> > Thanks!
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Olubunmi\_Junaid](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/olubunmi_junaid/32/16489_2.png) [@Olubunmi\_Junaid](https://forum.getodk.org/u/Olubunmi_Junaid)\
**Post date:** [March 19, 2014, 12:51pm UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031/3 "2014-03-19T12:51:09Z")

</div>

Havey,

Further break it down for me. I will and can be of help.  
Plant types are select1 and when 1 is selected Seed sample should auto fill  
(using acknowledgment ) a fixed integer figure or random, right?

> **···**
>
> On Tuesday, 18 March 2014 00:18:24 UTC+1, havey dewlett wrote: \> \> Basically I'm trying to automatically fill fields consecutively between \> groups. \> \> Example: \> Survey 1 \> Basic survey information (date, location, surveyor) \> Plant data (start groups) \> Plant 1 (group 1) \> Plant type: A, B, or C\* (manually select)\* \> Seed sample #: \*3456\*\* (auto fill)\* \> Plant 2 (group 2) \> Plant type: A, B, or C\* (manually \*\*select\*\*)\* \> Seed sample #: \*3457\*\* (auto fill)\* \> Plant 3 (group 3) \> Plant type: A, B, or C\* (manually \*\*select\*\*)\* \> Seed sample #: \*3458\*\* (auto fill)\* \> Plant 4 (group 4) \> Plant type: A, B, or C\* (manually \*\*select\*\*)\* \> Seed sample #: \*1234\* \* (manually override, samples were not in \> order)\* \> Plant 5 (group 5) \> Plant type: A, B, or C\* (manually \*\*select\*\*)\* \> Seed sample #: \*1235\*\* (auto fill)\* \> Plant 6 (group 6) \> Plant type: A, B, or C\* (manually \*\*select\*\*)\* \> Seed sample #: \*1236\*\* (auto fill)\* \> End survey \> \> If anyone knows if this is possible and/or can simply point me in the \> right direction, that'd be a huge help! \> Thanks! \>

---

<div class="post-metadata">

**Author:** ![havey\_dewlett](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@havey\_dewlett](https://forum.getodk.org/u/havey_dewlett)\
**Post date:** [March 19, 2014, 5:32pm UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031/4 "2014-03-19T17:32:01Z")

</div>

Thanks everyone for your help! Here's what I've got.

Each plant group is set to auto-repeat, and the view is set as  
"field-list". So all fields within the group are shown at once.  
The "seed sample number" field is not dependent on the "plant type".

When each new "plant" group repeats I'd like the "seed sample number" to  
auto-fill with +1 the previous plant's "seed sample number". The seed  
sample number is an integer in this example. I'd also like to repeat  
"select\_one" and "text" fields based on previous entries, without +1 in  
those examples.

I'd also like the value to be editable because the sample number  
occasionally will be out of order. Which is what I tried to show here:  
...  
Plant 2 (group 2)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _3457_\* (auto fill)\*  
Plant 3 (group 3)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _3458_\* (auto fill)\*  
Plant 4 (group 4)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _1234_ \* (manually override, samples were not in  
order)\*  
Plant 5 (group 5)  
Plant type: A, B, or C\* (manually **select** )\*  
Seed sample #: _1235_\* (auto fill)\*  
...

I tried using an indexed-repeat but can't get it to work.  
In an excel spreadsheet I have the field "seed\_sample\_number" and in the  
"calculate" variable column I have:

"indexed-repeat(${seed\_sample\_number}, ${plant\_group}, (position(..)-1))+1"

But when I try to upload to aggregate I get an error associated with bad  
coding.

_"Javarosa failed to construct a FormDef. Is this an XForm definition?"_

Through my own troubleshooting I've determined that the formula is correct  
because, if I create a new field within the group (ex: "test\_field") and  
put the same formula (still referencing the "seed\_sample\_number" field) in  
the "calculate" column, it will upload. Then when I test it on the device,  
I enter a value in "seed\_sample\_number" (ex: 1001) and go to the next group  
and the "test\_field" will be auto-filled with 1002! So it works! BUT not,  
because I can't get that value in the correct field. Even if I leave the  
"test\_field" and try and auto-fill the "seed\_sample\_number" by referencing  
the "test\_field" I get the same errors.

I also tried manually uploading the XML to my Android device, opened the  
form and got the error:

_"Dependency cycles amongst the xpath expressions in relevant/calculate"_

This made me think the form doesn't know how to calculate the first value  
when there is no previous group to reference?

To eliminate that idea, made the formula an IF statement\*, where _IF_ the  
position number was 1 (first group) then it would return a "0" instead of  
running the formula.  
\*I couldn't find any documentation on writing an IF statement but I think  
the syntax is correct.

"if(position(..)\>1, (indexed-repeat(${seed\_sample\_number}, ${PlantData},  
(position(..)-1))+1), 0)"

That didn't work. Still got the same errors. I think I'm either going about  
this at the wrong angle, and I should try using another method, in which  
case I'm open to all suggestions! Or, I'm really close and am missing  
something I can't think of.

I attached the Excel file and corresponding XML.

_Long-story short:_  
I'm trying to auto-fill a field in a repeat group, by referencing the same  
field in the previous repeat of that group. Currently I'm trying to use the  
"indexed-repeat" function, but am getting circular reference/dependency  
cycle errors.

_Thanks!_

[plant.xlsx](https://getodk.b-cdn.net/uploads/default/original/2X/e/e19ec10f18b7e19af39cfec0465bf20a9635e1ed.xlsx) (10.4 KB)

[plant.xml](https://getodk.b-cdn.net/uploads/default/original/2X/1/16a275df1eb87beda59298a256491cebd91e8dab.xml) (3.25 KB)

> **···**
>
> \> Further break it down for me. I will and can be of help. \> Plant types are select1 and when 1 is selected Seed sample should auto \> fill (using acknowledgment ) a fixed integer figure or random, right? \>

---

<div class="post-metadata">

**Author:** ![DamLin](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@DamLin](https://forum.getodk.org/u/DamLin)\
**Post date:** [September 26, 2014, 10:24am UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031/5 "2014-09-26T10:24:25Z")

</div>

Did you manage to resolve this issue?

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [September 26, 2014, 7:55pm UTC](https://forum.getodk.org/t/auto-fill-consecutively-between-groups/3031/6 "2014-09-26T19:55:44Z")

</div>

This is fundamentally not possible with XForms as implemented in javarosa.

You are seeking to set a 'default' value that can be overridden or  
accepted, but defaults are not available in ODK Collect except as values  
supplied in the form definition and, for repeat groups, identified with a  
jr:template attribute.

In these cases, they can only be constant values -- not functions.

> **···**
>
> On Fri, Sep 26, 2014 at 3:24 AM, DamianLindley via ODK Community \< opendatakit@googlegroups.com\> wrote:
> 
> > Did you manage to resolve this issue?
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
