Bulk saving of data values in Android custom app

We are planning to develop an Android app with DHIS2 Android SDK. We have a requirements to push hundreds of datavalues in bulk in database. I found this code in documentation -

DataValueObjectRepository valueRepository = d2.dataValueModule().dataValues()
    .value("periodId", "orgunitId", "dataElementId", "categoryOptionComboId", "attributeOptionComboId");

Which is setting value 1 by 1. Is there a bulk method - as we can do using API calls?

Hi @Mahmud,
I’m not an expert though, I’m sensing that the mentioned code is for submitting a dataelement’s value to the local repository only. Bur, once you execute the ‘Sdk.d2().dataValueModule().dataValues().upload()’ command, the SDK will submit all the data values from local repository to the server.
Hope this will help you till someone come to rescue you.

1 Like

Hi @Mahmud! :wave:

As @RahmanMonjur rightly says, the method you refer to is used to store the data in the device database. And indeed, to upload the data values to the server you have to call the d2.dataValueModule().dataValues().upload() method;

To learn more about the aggregated data workflow you can see more information here:

Feel free to reach out to us whenever you have more questions about how to use the DHIS2 Android SDK.

Hi @marcos.campos
Uploading data in bulk is fine. I am pointing to saving data in bulk. In our workflow, we will generate at least a few thousand datavalues and save in local db. I guess we have to do it one by one?

Hi @Mahmud,

yes, you are right, saving datavalues to the local db must be done one by one. If the main concern is about performance, saving datavalues to the local db is very quick, so you don’t have to worry so much about that. Regarding code complexity, I think the complexity is similar between creating the datavalues in memory in order to save them in bulk, and storing them in the database directly.

Regarding performance, the actual bottleneck is the upload to the server, and here the sdk uploads in bulk.

Hope it helps, and please let me know if I missed something.

Thanks to all for the guidance…will try.