Enketo Web surveys - using defaults parameter to set repeat item fields after first index

We are creating survey links for our users with prefilled defaults from previous submissions.
We use Enketo for our surveys, and we use the ?d[<key_name>]=<value> query parameters to prefill the survey. This has been working so far, but the issue comes in with the repeat block sections. We are able to set the first item in a repeat block using the method mentioned above, but subsequent repeat items cannot be set using that syntax.

Example:

Snap shot of example submission
{
    ...
    "username":"test_psa",
    "generalgroup/ggcmain":"mowing pruning herbicide",
    "generalgroup/herbicide":[
       {
          "generalgroup/herbicide/herbappmethod":"dry",
       },
       {
          "generalgroup/herbicide/herbappmethod":"liquid",
       }
    ],
    ...
}

Basic Enketo Defaults URL Format
`https://enketo.domain/survey/link?d[<key_name>]=

For this example we have tried the following formats:

One)
https://enketo.domain/survey/link
    ?d[username]=test_psa
    &d[generalgroup/ggcmain]=mowing pruning herbicide
    &d[generalgroup/herbicide/herbappmethod]=dry
    &d[generalgroup/herbicide/herbappmethod]=liquid

This format will set the herbappmethod of the first repeat item, but will not create and set the second one. What acrtually happens is that the first repeat item gets populated with liquid

Two)
https://enketo.domain/survey/link
    ?d[username]=test_psa
    &d[generalgroup/ggcmain]=mowing pruning herbicide
    &d[generalgroup/herbicide[0]/herbappmethod]=dry
    &d[generalgroup/herbicide[1]/herbappmethod]=liquid

This format will not set either fields.

Three)
https://enketo.domain/survey/link
    ?d[username]=test_psa
    &d[generalgroup/ggcmain]=mowing pruning herbicide
    &d[generalgroup/herbicide[0]/generalgroup/herbicide/herbappmethod]=dry
    &d[generalgroup/herbicide[1]/generalgroup/herbicide/herbappmethod]=liquid

This format will not set either fields.

To anyone who ends up here, and needs to duplicate a submissions with repeat blocks, using Kobo & Enketo I was able to achieve this by using the following request flow

### @name duplicate_survey
POST https://kf.kobotoolbox.org/api/v2/assets/<XFORM_ID_STRING>/data/<SUBMISSION_ID>/duplicate/
Authorization: Token <KOBO_USER_API_TOKEN>
Accept: application/json
Content-Type: application/json

### @name get_edit_survey_link
GET https://kf.kobotoolbox.org/api/v2/assets/<XFORM_ID_STRING>/data/<SUBMISSION_ID>/enketo/edit/?return_url
Authorization: Token  <KOBO_USER_API_TOKEN>
Accept: application/json
Content-Type: application/json
1 Like

@trevorjpuckett, thank you for sharing this with the entire community! :bowing_man: :pray: :tada: