Custom Business Logic Issues

Hi,
I’m facing multiple issues while creating/debugging/deploying custom business logic. The language is JS. I understand that custom logic debugging can’t be done in-built REST method, so I’m running it on JS inside a browser console. I’m using the basic codes from this guide - https://backendless.com/documentation/business-logic/js/bl_custom_events.htmI. Issues are below

    Many times I'm getting this error in debugging "userRole":["NotAuthenticatedUser"],"userId":null. This occurs even if I'm logged in as a user. Code working in debug fails when deployed. Returns either 400 error or 15000 error or blank response.
Is there anything I'm doing wrong here? Code is as below

On server side:

Backendless.ServerCode.customEvent('testy', function(req) {
 console.log( "event arguments: " + req.args );
 return req.args ;
});


On client side:

ar eventArg = user;
var successHandler = function( response ) {console.log(response)
};
var errorHandler = function( response ) {
};
Backendless.Events.dispatch( "testy", eventArg, new Backendless.Async( successHandler, errorHandler ) );


When ASYNC is checked, returns blank; when ASYNC is unchecked returns 400 error; when ASYNC parameter is removed, returns 15000 error.

Please help.

P.S. Why can’t I see the deployed code?

Hi!
JS custom business logic currently available only in debug mode.

Other issues we will try to reproduce.
Regards,
Kate.

Ah. Okie.

Hi Kate,

Can you provide a timeline by when JS custom business logic will be made fully functional? Does the statement “Support for custom server-side code in JavaScript is now available” refers to this video - https://www.youtube.com/watch?v=6WKJBaDeWU8 …? If yes, can you please guide me to the docs where I get read more on them?

Hi Tallenge,

Currently we plan to release it in 2-4 weeks.

Hi Sergey,

Just a clarification, I may be misinterpreting something. What does “Support for custom server-side code in JavaScript is now available” mean on the page https://backendless.com/parse-to-backendless-migration-guide/ then?

It means you can already create some JS business logic and test it in debug mode, but the production mode is not yet available: https://backendless.com/documentation/business-logic/js/bl_deploy_to_production_js.htm

Ah. Ok. I was very confused. I had lines of code written and it was not working.
Thank you for clearing it out. I guess I’ll revisit after a couple of weeks then.
Thank you :slight_smile:

Hi. Any update on this?

No, it is not ready yet.

Hi guys. Any update or timeline for this feature?

Eagerly waiting for migration.

It is in production now

Hi I’m not sure why this topic is closed as “Solved” but as of yesterday, the errors mentioned above are still present and I can’t still deploy the JS code. Has there been any change? I may be wrong, but I’m not sure if I’m following your terminology of “in production now”.

I marked as “Solved” when we updated the production servers with the infrastructure supporting JS event handlers.

How do you deploy your code? Could you show the output of the deploy command you get?

Hi Mark,

I’m using the basic code mentioned in the documentation here - https://backendless.com/documentation/business-logic/js/bl_custom_events.htm

Backendless.ServerCode.customEvent('tester', function(req) { 
 console.log( JSON.stringify(req) ); 
 return {status:"Event Processed"}; 
}, true);

    When I do npm run debug, the outputs in the command console is shown in image 1 Image 2 shows the output in the browser console. It's the same during debugging and also after running npm run deploy Image 3 shows the blank js file on server side after running npm run deploy.

The code in image 3 is the result of code generation. It does not change when you deploy your code to Backendless. It simply is a visualization through the code of the event handlers, timers and custom events you created in console. This is why the tab where that code is shown is titled “Code Generation”. Currently the Business Logic screen does not show the actual code that is deployed, however, you can see it in the Files section of Backendless Console.

I hope this answers your question and resolves the confusion.

Regards,
Mark

Hi Mark. What about the outputs in 1 & 2?

1 shows an authentication error and 2 shows empty return from the API call. Is there anything I’m doing wrong here?

I do not see any errors in (1). userRoles:[“NotAuthenticatedUser”] indicates that the user that made the call belongs to the NotAuthenticatedUser role, that’s all.

For (2), please check in the browser’s debugger what the “response” object contains (just set a breakpoint and inspect the object).

The response object is just a blank object. There is nothing in it.

Update: Synchronous calls are returning the required output.

I have modified my code to make use of synchronous calls. Everything is working fine as it should. Thank you for responding patiently. I’ll start migrating the app now.