Thank you very much Dears @mtuchi and @aleksa-krolls for your helpful posts.
it seems to be progressing well!
Now, i received data from Kobotoolbox for every submission but the code early shared by Emmanuel has some errors :
TypeError: TypeError: Cannot read properties of undefined (reading 'filter')
{"message":"TypeError: Cannot read properties of undefined (reading 'filter')","name":"RuntimeError"}
Check state.errors.fcf845b0-c5ba-45e0-adba-c735e58d8a9a for details.
Edge function (state) { return Boolean(!state?.errors?.["fcf845b0-c5ba-45e0-adba-c735e58d8a9a"] ?? true) } returned false; e76bed8b-06e5-4d63-8107-d30d2860dbc9 will NOT be executed
Run complete with status: fail TypeError: TypeError: Cannot read properties of undefined (reading 'filter')
Below is the code with this issue : (intermediate common adaptor step between webhook and DHIS2)
fn((state) => {
const { results } = state.data;
state.dataValues = results
.filter((rs) => rs.mad1 === "Fievrevalleerift") // Filter data
.map((rs) => ({
categoryOptionCombo: "Prlt0C1RF0s", //Fixed <1yr
dataElement: "x3Do5e7g4Qo", // OPV0 doses given
value: rs.NbreMorts, //# of OPV0 doses given
// value: '520',
}));
// Remember to remove this console.log, when done debugin
// console.log("Mapped DataValues", state.dataValues);
return state;
});
And for your information, i changed the form. Below is the json input which has been received :
{
"data": {
"Grp_troupeau/NbreMalades": "15",
"Grp_troupeau/Sexe": "m_le",
"GrpAgent/Adresse_professionnelle": "Test",
"Numero": "6786",
"_xform_id_string": "aKeNifn4yEDKri9M6NbBK2",
"GrpAgent/TitreAgent": "Assistant",
"GrpLocSuspicion/Nom_aire_dabattage": "Test",
"_submission_time": "2024-03-27T11:39:42",
"Grp_date_suspicion/Date_premier_signe": "2024-03-20",
"GrpAgent/Pr_noms_et_nom": "Test",
"GrpAgent/StatutAgent": "prive",
"GrpLocSuspicion/Wilaya": "Assaba",
"meta/instanceID": "uuid:f8e72b9c-dcbd-42be-8e92-cade68b69b35",
"_id": 325101636,
"__version__": "v8QUwvpCZJ33vba7ujfeAz",
"_uuid": "f8e72b9c-dcbd-42be-8e92-cade68b69b35",
"GrpMaladieEvol/liste_lesions": "hypertrophiefoieFVRL",
"_submitted_by": null,
"_tags": [],
"ajouter_un_prelevement": "non",
"GrpLocSuspicion/Commune": "Hseiy Tin",
"Grp_troupeau/effectif": "34",
"_notes": [],
"formhub/uuid": "92241f7470e842308405ee21e2219dc3",
"GrpMaladieEvol/qMad1": "Fievrevalleerift",
"_validation_status": {},
"_geolocation": [
null,
null
],
"Voulez_vous_ajouter_des_mesure": "non",
"Grp_date_suspicion/Date_de_rapportage": "2024-03-20",
"Grp_troupeau/NbreMorts": "9",
"_attachments": [],
"GrpLocSuspicion/lieuSuspicion": "aire_abattage",
"Grp_date_suspicion/Date_de_declaration": "2024-03-20",
"GrpMaladieEvol/liste_signes": "FrequenceeleveavortementsFVR",
"GrpLocSuspicion/Moughataa": "Boumdeid",
"Grp_troupeau/Age": "adulte",
"_status": "submitted_via_web",
"Grp_troupeau/liste_anisensibles": "BovinsFVR"
},
"request": {
"headers": {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"content-length": "1456",
"content-type": "application/json",
"host": "app.openfn.org",
"sentry-trace": "f2c9ca96d29f4b91bafc6e1c0cc0d862-8d94d9b6177af132-0",
"user-agent": "KoboToolbox external service #h4vU7brhnnwnH2CmVc3Cq5",
"via": "1.1 google",
"x-cloud-trace-context": "178dc072b7819dd462b16fbb392504b1/6785961645902563113",
"x-forwarded-for": "54.144.106.179,34.36.242.233",
"x-forwarded-proto": "https"
}
}
}