Is it possible to have a custom function in Custom Business Logic without a trigger?

So far Backendless supports all my needs in terms of migrating from Parse.

The one thing that i can’t seem to find though is if it’s possible to create a function in custom business logic code, call this function from within my project and then return values without the need of a trigger on a data table for example?

An an example of this would be a cloud code function which i have in parse which you can see below.

This makes an api request within the cloud function and then returns data in the response. In my swift project i could just call this function by specifying the name and passing the parameters into the function as well as you can see below this with an example from Parse.

// Example of function in the cloud
Parse.Cloud.define("getNewsData", function (request, response) {




    Parse.Cloud.httpRequest({




        method: 'GET',
        url: 'https://www.kimonolabs.com/api/546i5zru?apikey=bFzve31Y3BSdxkoErnP587LRuGIEFckH',
        headers: {
            'Content-Type': 'application/json;charset=utf-8'
        },
    }).then(function (httpResponse) {
        response.success(httpResponse.text);
    }, function (httpResponse) {
        response.error('Request failed with response code ' + httpResponse.status);
    });








});
// Example of calling a cloud code function in my project
PFCloud.callFunctionInBackground("getNewsData", withParameters: ["key1":"xxxxxxxxx"]) {
  (response: AnyObject?, error: NSError?) -> Void in
print(response)
}

Hi Tunde,

There is something similar in Backendless. We call it “custom events”. You can read about the feature at:
https://backendless.com/documentation/business-logic/java/bl_custom_events.htm

Regards,
Mark

@Mark: For those unfamiliar with Java and the Java Backendless SDK, are there any examples that would speed up the learning curve? Any example that loads some tables and returns the data would be great. Thanks!

Miroslav, example in what language? Server-side code in Backendless is available in Java, PHP and JS.

Java would be the best as there’s already a webinar. But frankly - whatever works, I just need to get the job done, I’m not native in any of these languages.

Examples for loading data from tables are included in the documentation. For example:

https://backendless.com/documentation/data/ios/data_search_and_query.htm

I’m feel like we’re not at the same page.

Me: Can I have Java example?
You: Do you want Java, PHP or Javascript?
Me: Java.
You: Here’s link to iOS documentation.

Would you please give me a Java custom logic example of THIS particular request handler? Thank you very much.

Please do not give me a reference:
https://backendless.com/documentation/business-logic/java/bl_custom_events.htm

As in the reference there’s only a hello world level of complexity example and I’m really struggling to figure out more complex logic without a point of reference.

Thanks for understanding, for your patience and kind help.

I’m sure you guys have tons of examples. Could you just copy-paste one of them here? That’ll take you like 1 minute. It doesn’t have to be exactly the same, but something I can get the ah-ha moment from, because after reading the documentation, I’m really clueless. Thanks.

Sorry, Miroslav, it was meant to be a link to the java section of the doc (which is 2 clicks away from the link I gave you).

You asked “Any example that loads some tables and returns the data would be great”. An example that does just that is right there in the doc. I am struggling to understand why that is not clear and which part makes it difficult. Making an API call within custom business logic is identical to an Android app.

Rather than solving it in a pointed manner, please walk me through your thinking process with references to the docs you used and explaining what’s not clear. That will help us in understanding where we fell short with the docs and how we could improve them.

Regards,
Mark

Hi Mark,

my thinking process:

  1. I need to implement server-side code in order to create recurring timers, custom business logic etc.
  2. I look into the documentation, nice I see the reference. Ok, I understand that I can put custom logic before and after events.
  3. I look at the tutorial. Excellent! There’s a CodeRunner. The setup is really smooth and easy. Big Thanks for that.
  4. First problem - I didn’t follow the instructions to the letter and created async method and thought I could debug it.
  5. After a little big of googling I found out that I cannot debug async functions in code runner. I rewatched the video few times to make sure I’m not missing anything.
  6. Great, now it’s time to write some code, but I’m puzzled on how to start, I don’t see any real-world examples in the docs.

Here you come to resque with

Key #1 - The Backendless Custom Java Backend Logic uses the same Framework as the Android

I’m not saying it wasn’t in the documentation (although I didn’t find it), but I believe that’s something that should be mentioned in:
https://backendless.com/documentation/business-logic/java/bl_overview.htm

Good. Now I have something I can work with. But the examples for the backend logic are still missing. How do I implement a custom event handler to be parsed automatically to my Swift BackendlessEntity subclasses?

You say there’s an example that loads some tables and returns the data. Do you refer to this page?
https://backendless.com/documentation/business-logic/java/bl_custom_events.htm

This is what I implemented:

@Override 
public Map handleEvent( RunnerContext context, Map eventArgs ) 
{ 
 
 String whereClause = "isOver = 0"; 
 BackendlessDataQuery dataQuery = new BackendlessDataQuery(); 
 dataQuery.setWhereClause( whereClause ); 
 BackendlessCollection<Challenge> result = Backendless.Persistence.of( Challenge.class ).find( dataQuery ); 
 
 // add your code here 
 HashMap hashMap = new HashMap() 
 hashMap.put("result", result.getData()); 
 return hashMap; 
}``` 
Is this even correct? 
 
 
What structure should I use for the hashMap. Again, please note that I'm not fluent in Java just like many other iOS developers. But we'd still love to create the custom backend logic without too much hustle. So some step-by-step, case-by-case tutorial with real world examples would be very nice, save people time and make the service much more beginner-friendly. 
 
 
I can keep asking many questions, but as I said, if there was a full programming guide or tutorial or at least example of the entire implementation, it would fill the holes in my knowledge. 
 
 
Thank you for your patience.

EDIT:
bonus question: So I can also send push notifications and use all parts of the Backendless framework on the backend just like I would in an Android app?