{
"token": "",
"formVersion": "",
"formId": "phenology001",
"data": [
{
"today": "2019-08-26",
"start": "2019-08-26T21:09:48.420Z",
"observation": [
{
"stage": "1",
"picture": {
"url": "https://<mypictureurl>",
"type": "image/jpeg",
"filename": "1566853816709.jpg"
},
"notes": "Test note"
},
{
"stage": "2",
"picture": {
"url": "https://<mypictureurl2>",
"type": "image/jpeg",
"filename": "1566853849716.jpg"
},
"notes": "Test note 2"
}
],
"name": "Andrew",
"location:Longitude": null,
"location:Latitude": null,
"location:Altitude": null,
"location:Accuracy": null,
"instanceID": "uuid:f38ecef5-117a-44b3-a443-7d7d3b1ad3a6",
"imei": "867440036085345",
"end": "2019-08-26T21:11:03.306Z",
"date": "2019-08-26",
"*meta-ui-version*": null,
"*meta-submission-date*": "2019-08-26T21:11:21.838Z",
"*meta-model-version*": null,
"*meta-is-complete*": true,
"*meta-instance-id*": "uuid:f38ecef5-117a-44b3-a443-7d7d3b1ad3a6",
"*meta-date-marked-as-complete*": "2019-08-26T21:11:21.838Z"
}
],
"content": "record",
"__query_params": {}
}each(
dataPath("data[*]"),
combine(
sql( function(state) { return (
`INSERT INTO log_entry (odk_instance_id, logger_name) VALUES ('`
+ dataValue("*meta-instance-id*")(state) + `', '`
+ dataValue("name")(state) + `');`
)}) ,
each(
dataPath("observation[*]"),
sql( function(state) { return (
`INSERT INTO log_entry_observation `
+ `(odk_instance_id, stage, notes) VALUES ('`
+ `123` + `', `
+ dataValue("stage")(state) + `, '`
+ dataValue("notes")(state) + `')`
)})
)
)
);Executing SQL statement: INSERT INTO log_entry (odk_instance_id, logger_name) VALUES ('uuid:f38ecef5-117a-44b3-a443-7d7d3b1ad3a6', 'Andrew');
Executing SQL statement: INSERT INTO log_entry_observation (odk_instance_id, stage, notes) VALUES ('123', 1, 'Test note')
Finished.each( dataPath('data[*]'),alterState((state) => {
//store the meta-instance-id on each observation, so that it can be accessed
//Also add a counter/index to create a unique id for each observation
var odk_id = state.data["*meta-instance-id*"];
var max = state.data.observation.length;
for (var i = 0; i < max; i++) {
state.data.observation[i].parentrec = odk_id;
state.data.observation[i].unique = odk_id + "-"+ i.toString();
}
return state;
});--
You received this message because you are subscribed to the Google Groups "OpenFn Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openfn+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openfn/569a310a-5942-4fd1-820e-7951d3f7463e%40googlegroups.com.