I have no idea what the problem is.
My code:
/*Created on 08/22/2017 11:59:34.*/
class MyService {
/**
* @param {String} name
*/
helloWorld(name) {
return new Promise((resolve, reject) => {
var queryBuilder = Backendless.DataQueryBuilder.create();
getIngredients( queryBuilder );
function getIngredients( queryBuilder ) {
Backendless.Persistence.of("Ingredients").find( queryBuilder )
.then( handleResult )
.catch( handleError );
}
function handleResult( ingredients ) {
printIngredients( ingredients );
if( ingredients.length > 0 ) {
queryBuilder.prepareNextPage();
getIngredients( queryBuilder );
}
else {
console.log( "Reached the end of collection" );
}
}
function handleError( error ) {
console.log( "Server reported an error - " );
console.log( error.message );
console.log( error.errorCode );
return "E-"+error.message;
}
function printIngredients( ingredientsCollection ) {var ingredients = [];
var ing = "";
for( var i in ingredientsCollection )
ing = ing + ingredientsCollection[ i ].namePrint + ",";
var data = [];
for (var i = 0; i < ing.length; i++){
data.push(ing.charCodeAt(i));
}
var savedFile = Backendless.Files.saveFile( "testfolder", "test.txt", data, true)
.then( function( fileURL ) {
resolve(fileURL);
})
.catch( function( error ) {
reject(error.message);
});
}
});
}
}
Backendless.ServerCode.addService( MyService );