Hi George,
Please see below:
===============================
When creating the custom event handler in Console, do i select Language Java or JS, am developing in Java so i guess the former but only JS generates custom event handler code to edit and deploy, Java doesn’t.
You can use either Java or JavaScript, whichever you feel more comfortable. The code is generated for both, however, you can edit the code and then deploy inside of console only for JS. For Java, you need to download generated code, edit/compile/deploy from your own computer. You can download the code using the Download menu located on the same screen.
For my use case, getting the object count on 4 tables and summing them up, how will i structure my code? Put 4 of the above getObjectCount code, one for each Table inside the below block?
Backendless.ServerCode.customEvent('sumOfObjectCounts', function(req) {
//add your code here
getObjectCount (for Table1)
getObjectCount (for Table2)
getObjectCount (for Table3)
getObjectCount (for Table4)
});
Your custom event should return objects counts for the specified tables. The return type of a custom event is an object. See the doc here:
https://backendless.com/docs/bl-js/doc.html#bl_custom_events
I suppose the returned object may look like this:
{
“table1”: objectCountForTable1,
“table2”: objectCountForTable2,
“table3”: objectCountForTable3,
“table4”: objectCountForTable4
}
where objectCountForTable1, objectCountForTable2, objectCountForTable3, objectCountForTable4 are values obtained with the API. Keep in mind that when you use Backendless API inside the business logic, the calls must be non-blocking, so you should use promises to get the return values and then assemble the final object.
What does the API for dispatching custom events below do exactly?
Backendless.Events.dispatch( "foo", args, new AsyncCallback <Map>()
{
Am confused between
Backendless.ServerCode.customEvent() {}
and
Backendless.Events.dispatch(){}
“Backendless.ServerCode.customEvent” is used to declare your custom event on the server side. “Backendless.Events.dispatch” is used to invoke the custom event from the client application.
Hope this helps.
Mark