Im trying to get the SendMessage function to run, but it wont run when I place it inside the data request (Backendless.Data.of()find()). It runs fine if its outside of the data request though. I tried adding async and await to the function and call but that didnt seem to work. Any ideas? Thanks
function GetLeaderboardData()
{
//this function runs fine here but not as a result request from data find
// SendMessage();
Backendless.Data.of( "Leaderboard_Game01" ).find()
.then( function( result ) {
SendMessage();
})
.catch( function( error ) {
// use the .statusCode or .message on the "error" object
// to see the details of the error
});
}
If you declare a plain function without “async” or “await” and put a “console.log” statement in there, is it called?
I have no idea how to get the debug/coderunner environment to work. I tried following the help but when I download the files they are not as described in the help. So, unfortunately I’m still stuck with debugging using the business logic tab and messages, which is very painful. I’m guessing console.log is pretty useless without proper debugging. I think a lot of the help seems to expect that I already know how to do a lot of this stuff.
What is your app ID? I’d like to verify that files are missing in the project templates.
Thanks,
Mark
App Id is: 6FB0797D-AFB7-3B57-FFAB-BCEABA9E4500
I dont understand why (in the same function in code) my message runs but if I replace it with a data update (or anything to do with data) it just doesn’t run/update the data table.
For example, this works fine…
async function SendMessage()
{
await Backendless.Messaging.publish('default', 'Hello from a '+timerLength+' second timer sent at: '+currentTime+' Data is: '+firstData, new Backendless.PublishOptions({ subtopic: '', headers: {"timerStartedAt":currentTime,"timerLength":timerLength} }), undefined)
}
…but this doesn’t work at all…(even though the table and objectId all exist)
async function SendMessage()
{
await Backendless.Data.of( "Game_Data" ).saveSync( { objectId: "1802CECF-58DB-67EC-FF7B-5ADE11018B00",lastTimerStartedAt: "kjdsbcksjdnbcljds"} );
}
Just downloaded the JS API Service template for your app. Here are the contents of the zip file:
http://support.backendless.com/public/attachments/68b8838c9e928906ff79a90593b97fd2.jpg</img>

Genius! That works Thank you! I guess I need to read up on the differences.
However, I’m trying now to retrieve the data with a non blocking function as above but the SendMessage is never triggered. Maybe it’s the wrong syntax? (“Leaderboard_Game01” table exists)
function GetLeaderboardData()
{
Backendless.Data.of( "Leaderboard_Game01" ).find()
.then( function( result ) {
SendMessage();
})
.catch( function( error ) {
});
}
});
Try also to add some logging to the ‘catch’ clause, so that you don’t miss any errors if any.
Hi Simon
It should works:
class MySuperClass{
async mySuperMethod(){
const dataResult = await Backendless.Data.of( "Leaderboard_Game01" ).find()
const publishResult = await Backendless.Messaging.publish('default', ....)
return dataResult
}
}
Regards, Vlad
Thanks. Any way to do it without using a separate class? The function is actually executed when a timer starts so I just really need it as a function within the timer code.
Ah I figured it out.
The calling function needs to be :
await GetLeaderboardData();
and then the rest of the function needs to be:
async function GetLeaderboardData()
{
await Backendless.Data.of( "Leaderboard_Game01" ).find()
.then( function( result ) {
firstData=result;
SendMessage();
})
.catch( function( error ) {
});
}
So, its the old ‘async’ issue again. Thanks
You were downloading wrong project because you have selected wrong language (CODELESS):
http://support.backendless.com/public/attachments/3a771153bf99bd03fedf7925e9f4fd49.jpg</img>
If you follow the quick start guide for API services, it will walk you through each step:
https://backendless.com/docs/bl-js/doc.html#bl_basic_quick_start_guide_js
