The error is in the console.log
I need these to execute on a screen show, but because of the error, I tried moving it to a button push. the show button is to show the list of messages in database.
When I click Incoming:
When I click outgoing:
Some records do get written, but I need it to work without the error as I need to retrieve all send and received messages from twilio, then record those that are not yet recorded. The issue seems to be with the app and the appery database. I don't get any issues with the twilio db.
here is the code that runs on the click:
//this function should run on success of the Check_Message_ID query.
function makeSuccessFunction(twilioId,currMsg){
return function successFunction(data) {
//this checks to see if there is any data and if not runs a record to database event.
if (data === null || data.length === 0){
Apperyio.storage.messageDB.set(currMsg);
//create service
sms_local_db.execute();
};
}
// this grabs the current messages and places them in an array
var messages= Apperyio.storage.messageDBData.get();
var currMsg;
var twilioId;
// this loops for each mesages
for (i = 0; i < messages.length; i++) {
currMsg = messages;
//this grabs the current looped array and places it in a storage variable
Apperyio.storage.messageDB.set(currMsg);
//this grabs the current value of twilioId to use in query
twilioId = Apperyio.storage.messageDB.get("$['twilioId']");
// this is the query of the appery database that needs to run once on every pass
Check_Message_ID.execute({
data:{"where": '{"twilioId":"'+twilioId+'"}'},
success: makeSuccessFunction(twilioId,currMsg),
});
}