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 (10.4 KB)
plant.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?
>