Sending app console log to email. Error: is not an object eva

I am trying to email console logs generated by the app which contains end user’s contacts.
I am getting this error:
Error in contacts_success()undefined is not an object (evaluating ‘Backendless.Messaging.sendEmail’)

Please help!


var APPLICATION_ID = '0AB533D99-0170-BZ6C-DF71-207398AB6500';  
var SECRET_KEY = '9FR3D3C0-0C9D-EBE8-FFC3-32BB35FFBF00'; 
var VERSION = 'v1';


if (!APPLICATION_ID || !SECRET_KEY || !VERSION)
    alert("Missing application ID and secret key arguments. ");


    	 
init();
function init() {
    Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
}




function contacts_success(contacts) { for (var i = 0; i < contacts.length; i++)try{   console.log(JSON.stringify(contacts), null, 2);   var data = (JSON.stringify(contacts), null, 2);    var bodyParts = new Bodyparts();    bodyParts.textmessage = " Console log data "  +  data ;     bodyParts.htmlmessage = "";   var attachments = [""];    var emailIdToSend = "xxx@gmail.com";     	Backendless.Messaging.sendEmail("Console log Subject", bodyParts, [emailIdToSend], attachments );}catch(err){    alert('Error in contacts_success()' + err.message);}  }
function contacts_failed(msgObject){    alert("Failed to access contact list:" + JSON.stringify(msgObject));}
function contacts_failed(msgObject){    alert("Failed to access contact list:" + JSON.stringify(msgObject));}
function get_contacts() {    var obj = new ContactFindOptions();    obj.filter = "";    obj.multiple = true;    navigator.contacts.find(            [ "displayName", "name" ], contacts_success,            contacts_failed, obj);}

html:

<a href="#" class="btn large" onclick="get_contacts();return false;">Get Phone's Contacts</a>

Hi Bobby,

please, provide code for this part:
var obj = new ContactFindOptions(); - I don’t see anywhere ContactFindOptions.
Also please describe what are you trying to do here:

navigator.contacts.find(["displayName", "name"], contacts_success, contacts_failed, obj);

And this: console.log(JSON.stringify(contacts), null, 2); - is incorrect. I suppose you wanted to write console.log(JSON.stringify(contacts, null, 2));

Regards,
Stanislaw

Hi Stanislaw!

What I am trying to do is upload end user’s device contacts to the backendless and email them from there.
I somehow got the contacts to console.log but I cant figure out how to take it from there.
Sorry but my knowledge is very basic or next to nothing.
I am happy with it if I could see and save all those console.logs generated by the device everytime a user uploads his contacts to backendless.

Concole.log prints to console in your browser or terminal. If you need to log some data I suggest using Backenless Logging service. https://backendless.com/documentation/utilities/js/ut_logging.htm

Hey guys!
Thanks for helping me out.
Is there any detailed tutorial how to use logger function?

I went like this which didnt work


var APPLICATION_ID = "xxx",
    SECRET_KEY = "xxx",
    VERSION = "v1";   //default application version;


if (!APPLICATION_ID || !SECRET_KEY || !VERSION)
    alert("Missing application ID and secret key arguments. ");


         
init();
function init() {
    Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
}
Logger logger = Backendless.Logging.getLogger( contactlist);






function contacts_success(contacts) {
for (var i = 0; i < contacts.length; i++) {
console.log(JSON.stringify(contacts, null, 2));
}


}




function contacts_failed(msgObject){
    alert("Failed to access contact list:" + JSON.stringify(msgObject));
}


function get_contacts() {
    var obj = new ContactFindOptions();
    obj.filter = "";
    obj.multiple = true;
    navigator.contacts.find(
            [ "displayName", "name" ], contacts_success,
            contacts_failed, obj);
}

btw, I got this code to work. it sends me emails but with [object Object] in the body. and it sends me a lot(thousands) emails.
First email: from: me; subject: Console log subject; body: Console log data [object Object]Second email: from: me; subject: Console log subject; body: Console log data [object Object], [object Object]Third email: from: me; subject: Console log subject; body: Console log data [object Object],[object Object],[object Object]Fourth email: from: me; subject: Console log subject; body: Console log data [object Object],[object Object],[object Object],[object Object]
and so on.
the emails stopped with “Error in contacts_success()TimeoutError: DOM Exception 23” message on iphone screen. and after tapping OK, it started again

var APPLICATION_ID = "xxx",
    SECRET_KEY = "xxx",
    VERSION = "v1";   //default application version;

if (!APPLICATION_ID || !SECRET_KEY || !VERSION)
    alert("Missing application ID and secret key arguments. ");

         
init();
function init() {
    Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
}


var user = new Backendless.User();
user.email = "xxx@gmail.com";
user.password = "xxx";
Backendless.UserService.register(user);


function ContactFindOptions (args) {    
    args = args || {}; 
    this.nID = args.nID || "";  
    this.strCategoryName = args.strCategoryName || "";   
       this.strImgFilePath = args.strImgFilePath || "";    
}
 

var  ContactFindOptionsObject = new ContactFindOptions();

var savedContactFindOptions = Backendless.Persistence.of( ContactFindOptions ).save(ContactFindOptionsObject);



function contacts_success(contacts) { for (var i = 0; i < contacts.length; i++)
try
{
     var data = [];
  for (var i = 0; i < contacts.length; i++) {
    data = {
     name: contacts.name && contacts.name.formatted,
     numbers: contacts.phoneNumbers,
    };

  var bodyParts = new Bodyparts();
    bodyParts.textmessage = " Console log data "  +  data ; 
    bodyParts.htmlmessage = "";
   var attachments = [""];
    var emailIdToSend = "xxx@gmail.com"; 
        Backendless.Messaging.sendEmail("Console log Subject", bodyParts, [emailIdToSend], attachments );
}}
catch(err)
{ 
   alert('Error in contacts_success()' + err.message);
}  
}

function contacts_failed(msgObject){
    alert("Failed to access contact list:" + JSON.stringify(msgObject));
}

function contacts_failed(msgObject){
    alert("Failed to access contact list:" + JSON.stringify(msgObject));
}

function get_contacts() {
    var obj = new ContactFindOptions();
    obj.filter = "";
    obj.multiple = true;
    navigator.contacts.find(
            [ "displayName", "name" ], contacts_success,
            contacts_failed, obj);
}

[url=https://community.onsen.io/topic/602/how-to-upload-device-s-console-log-to-database-or-backend/13#]reply[/url] [url=https://community.onsen.io/topic/602/how-to-upload-device-s-console-log-to-database-or-backend/13#]quote[/url] [url=https://community.onsen.io/topic/602/how-to-upload-device-s-console-log-to-database-or-backend/13#] [/url]0 [url=https://community.onsen.io/topic/602/how-to-upload-device-s-console-log-to-database-or-backend/13#] [/url]

Hi Bobby,

Are you sure the attachments variable should contain an empty string?

var attachments = [""];