Hey buddy,
this works:
/**
* Track temperatures
* @param {org.acme.securebox.GetTempDetails} GetTempDetails - temperatures to be processed
* @transaction
*/
async function GetTempDetails(uID){
var factory = getFactory();
var NS_M = 'org.acme.securebox';
var uniqueId = uID.orderId + "-" + uID.prodId + "-" + uID.secureBoxId;
var temperature = factory.newResource(NS_M, 'Temperature', uniqueId);
temperature.redTemp = [];
const temp = await request.get({ uri: '<myURL>? $filter= ORDERID eq "uniqueId" ', json: true });
//this data below is a sample of what comes back from request response assigned to `temp` (I can't call your request URI :-) - format your output if different
var temp = '{ "ID": "123", "ORDERID": "123", "date": "2018-01-01T00:00:00", "tempMin": "16", "tempMax": "24", "tempAvg": "20"}, { "ID": "456", "ORDERID": "456", "date": "2018-01-01T00:00:00", "tempMin": "16", "tempMax": "24","tempAvg": "20"} ';
// stringify results
var tempstr = JSON.stringify(temp);
// create an array of objects
var jsonobj = JSON.parse('[' + JSON.parse(tempstr) + ']');
for(i=0 ; i < jsonobj.length; i++ ) {
var redTemp = factory.newConcept(NS_M, 'TempReadings');
console.log("ID field for this array element is " + jsonobj[i].ID); // all good
var str = jsonobj[i].date + 'Z'; // supplied date in `temp` isn't truly DateTime so...
// convert the assumed string into an array.
// eg redTemp.redDate = [new Date('2011-04-11T10:20:30Z')];
redTemp.redDate = [new Date(str)];
redTemp.minTemp = [jsonobj[i].tempMin];
redTemp.maxTemp = [jsonobj[i].tempMax];
redTemp.avgTemp = [jsonobj[i].tempAvg];
// temperature.redTemp = [redtemp];
temperature.redTemp.push(redTemp);
console.log("temperature date for array redTemp element " + i + " is: " + temperature.redTemp[i].redDate);
} // end for
// save the order to the ledger
return getAssetRegistry(temperature.getFullyQualifiedType())
.then(function (registry) {
return registry.addAll([temperature]);
})
.then(function(){
// var CreateTempDetailsEvent = factory.newEvent(NS_M, 'CreateTempDetailsEvent');
// CreateTempDetailsEvent.uniqueId = temperature.uniqueId;
// emit(CreateTempDetailsEvent);
console.log("everything is done");
});
} // end function