Begin repeat in begin repeat

odk-collect

(SAJID AKHTER) #1

Dear All,

Pls help...

I have create a form and using begin repeat function, In begin repeat there is begin repeat but it is not working, pls suggest how I use begin repeat in begin repeat.

Regards
Sajid Akhter


(Grzegorz Orczykowski) #2

Hi @sajidakhter

could you attach your form?

Regards,
Grzegorz


(SAJID AKHTER) #3

Dear Grzesiek

Thanks for reply.

Pls download the file from given below mentioned link, first loop is working perfectly but in second loop it give error.

https://drive.google.com/open?id=1T6Sml9BEBGNTZsnAXbt519-qvjUm7suY

Regards
Sajid


(ARIF AZAD KHAN) #4

Use this revised XLS probably it will work. test1.xls (37 KB)


(SAJID AKHTER) #5

Dear Arif,

Thanks for your prompt response, i have upload the same form when second loop is start and reached to question no 213B it give error, pls download the error from mentioned below link.

https://drive.google.com/open?id=1XHUKBf_AZKxMzNO9sb72OrdPqFDTwu4W

Regards
Sajid


(ARIF AZAD KHAN) #6

can you please check it with the latest version of ODk collect. I have checked with Kobo collect and ODK collect both are fine to generate the desired repeat. Do not show this error you mentioned.


(SAJID AKHTER) #7

Dear Arif,

I am using ODK collect v1.8.1, still I am getting the same error, first loop is working fine when the second repeat come it start fine but when it reach to 213B, it give error message, when I press ok it will move.

https://drive.google.com/open?id=1XHUKBf_AZKxMzNO9sb72OrdPqFDTwu4W

Regards
Sajid


(ARIF AZAD KHAN) #8

In your case probably you need to use the index-repeating formula in the form or change the collect version (ODK collect version 1.12.2 is available in the play store). I do not which one is applicable to your current situation.


(Grzegorz Orczykowski) #9

@sajidakhter
It's logical to me that it doesn't work and I'll try to explain why:

As you know and as you said you have two repeated groups and they are nested (one inside another).
You try this:
indexed-repeat(${Q213B}, ${Repeat213b_f}, position(..))=1
where the first parameter ${Q213B} is a single choice question, the second parameter ${Repeat213b_f} is a group (which is inside another repeat group) and the last one position(..) is a position - number of group you pass as a second parameter.
So if position is 1 you refer to ${Repeat213b_f}[1]
if it's 2 you refer to ${Repeat213b_f}[2] etc.
The problem here is that ${Repeat213b_f} is inside another repeat group so we know which number of ${Repeat213b_f} you want but we don't know the number of the second group.

I tried this instead: indexed-repeat(${Q213B}, indexed-repeat(${Repeat213b_f}, ${Repeat_room_No}, ${calc1}), ${calc2})=1
where I calc positions bor both groups, but I can't convert such a form so I don't know maybe I do that in a wrong way or we don't support such a case.

@yanokwa @LN maybe you can help?

Regards,
Grzegorz


(Hélène Martin) #10

You can see at https://opendatakit.github.io/xforms-spec/#fn:indexed-repeat that the function description is indexed-repeat(nodeset arg, nodeset repeat1, int index1, [nodeset repeatN, int indexN]{0,2}). This is a little confusing but what it means is that to go multiple levels deep you can add more parameters.

Say you have a repeat called friends with a nested repeat called pets and that you want to get the name of your 3rd friend's 4th pet, you could use an expression like indexed-repeat(${pet_name}, ${pets}, 4, ${friends}, 3)

Here is a form that illustrates this.


(Grzegorz Orczykowski) #11

Thanks @LN!

@sajidakhter let us know if it works for you.


(Aurelio) #12

Hi @Grzesiek2010,

are you aware if in the meanwhile something got broken in the function position(..).

If I use the form posted by @LN it works for the first iteration of the repeat "friends".
All works well and the pet_count has a value.

If I add a second "friends" then when I get to "pets" the pet_count is not evaluated (empty or null).

If you test the form nested-indexed-repeat you can verify it.


(Aurelio) #13

Ok. Just realized that it's working in collect.
It was the Enketo preview not working.


(Tebo Kgweenyane) #14

In a Begin Repeat Statement where you have a list of choices to make, how do you ensure that you do not repeat the same choice that was previously selected?
For Example: Diesel, Petrol, Paraffin, LPG....How do I make my program to grey the one that has been previously selected to avoid repetition.

Thank You in advance for your responses.