Assigning Custom Role in JS on Users Entity

Tutorial: https://backendless.com/documentation/business-logic/js/bl_quick_start_js.htm
I am using JS in Business Logic using Events on Users Table after Register
Business Logic:
afterRegister.js

console.log( "Test");
req.user.email = req.user.email.toUpperCase();

Ran npm run debug
21:52:23.682 - Registering Model on https://api.backendless.com
21:52:24.121 - Model successfully registered
21:52:24.122 - Waiting for Server Code tasks…
I verified that event is registered in Debug tab and is Enabled.

curl -H application-id:"xxxxxxxx" -H secret-key:"yyyyyyyyy" -H Content-Type:application/json -X POST -d "{\"email\":\"P1@p.com\", \"password\":\"password\"}" -v https://api.backendless.com/v1/users/register

But i dont see any info on Server Code command window
Curl is getting run correctly and row is getting inserted to the Users Table as well. I even tried with other Table as well.
Looks like Server is not getting invoked…
What am i doing wrong here…?
Thanks
Sudheer

Could you please show the complete output from “npm run debug”?

Here it is:

> QuizApp-servercode@1.0.0 debug c:\Users\xxxxxxx\Downloads\QuizApp (1)
> coderunner debug
19:26:25.720 - CodeRunner(tm) Backendless Debugging Utility
19:26:25.720 - Copyright(C) 2016 Backendless Corp. All rights reserved.
19:26:25.720 - Version 1.2.4
19:26:27.694 - Starting Debug Code Runner...
19:26:27.709 - Building Model..
19:26:27.725 - Model Build completed: event handlers: 2, timers: 0, custom types: 1, services: 0, errors: 0
19:26:27.725 - Registering Code Runner on [url=https://api.backendless.com]https://api.backendless.com[/url]
19:26:28.282 - Runner successfully registered.
19:26:28.285 - Registering Model on [url=https://api.backendless.com]https://api.backendless.com[/url]
19:26:28.879 - Model successfully registered
19:26:28.879 - Waiting for Server Code tasks..

Thanks, Sudheer. What does the other handler do? Is it getting invoked?

Nope, 2 handlers are not getting invoked.

a. After Register on Users table
b. After Create on Grade Table (Custom table)

I can give me Application id if that helps to check this out, i can change it later

Hi Sudheer,

We looked into the problem and it is a bug in the core system - it does not issue events for the register API. An internal ticket has been created and is assigned to a developer.

Mark

Hello, Sudheer!

Can you try it again?
Thanks!

Hi Alexandr, I dont see any change compared to previous. Do i need to get any update?

I reset the connection and tried but still no luck… but this is what i found after i click reset connection under Debug Tab. Bold statement below… I tried to wait for sometime and click reset then i was seeing this and its consistent. btw, i was testing on User - after Register

Thanks

> coderunner debug

22:35:43.745 - CodeRunner(tm) Backendless Debugging Utility
22:35:43.750 - Copyright(C) 2016 Backendless Corp. All rights reserved.
22:35:43.753 - Version 1.2.4
22:35:44.072 - Starting Debug Code Runner...
22:35:44.090 - Building Model..
22:35:44.097 - Model Build completed: event handlers: 2, timers: 0, custom types: 1, services: 0, errors: 0
22:35:44.103 - Registering Code Runner on [url=https://api.backendless.com]https://api.backendless.com[/url]
22:35:44.681 - Runner successfully registered.
22:35:44.685 - Registering Model on [url=https://api.backendless.com]https://api.backendless.com[/url]
22:35:45.039 - Model successfully registered
22:35:45.041 - Waiting for Server Code tasks..
22:39:19.641 - New task arrived! [id:null]
22:39:19.646 - Received a shutdown request from Backendless

No, you’re not able to do any update. We shall keep on looking at this issue.

I’d like to ask you to add some other handlers ( for example, beforeLogin ) and try to invoke them. Notify us please about results.
Thank you!
Alex

Hi Alex,

I tried to add afterRegister on Users and afterUpdate on custom table.
Its always disconnecting,btw this is the info

> coderunner debug

22:29:46.637 - CodeRunner(tm) Backendless Debugging Utility
22:29:46.641 - Copyright(C) 2016 Backendless Corp. All rights reserved.
22:29:46.644 - Version 1.3.4
22:29:46.974 - Starting Debug Code Runner...
22:29:46.988 - Building Model..
22:29:46.997 - Model Build completed: event handlers: 2, timers: 0, custom types: 0, services: 0, errors: 0
22:29:47.298 - Registering Code Runner on [url=https://api.backendless.com]https://api.backendless.com[/url]
22:29:47.926 - Runner successfully registered.
22:29:47.928 - Registering Model on [url=https://api.backendless.com]https://api.backendless.com[/url]
22:29:48.303 - Model successfully registered
22:29:48.309 - Waiting for Server Code tasks..
22:30:33.037 - Debug Session ID doesn't exist on server
22:30:33.039 - Oops.. Looks like we were disconnected. Trying to reconnect..
22:30:33.044 - Registering Code Runner on [url=https://api.backendless.com]https://api.backendless.com[/url]
22:30:33.381 - Unable to register Runner. Runner registration failed because another code runner is already attached. Please wait for one minute before connecting again.

i tried to remove custom table Logic, still i see this error. btw, i dont have any logic in each function except one console statement.

Not sure if this is expected and i dont remember seeing this before.
In Backendless web Page of BusinessLogic, i keep seeing Reset Connection button appearing and disappearing.

Hi Sudheer!

Could you try to reset connection manually?
Also, this issue already resolved. Could you try again?
Regards,
Kate.

I switched my machine and now, still i saw the same issue. i am able to submit the tasks after i deploy it. might be some issue with debug version. btw, functionality is not working as expected. please do let me know if i am doing any thing wrong.

Code:

Backendless.ServerCode.Persistence.beforeCreate('Chapter', function(req) {
  console.log(req);
  req.item.ChapterName = req.item.ChapterName.toUpperCase();
  console.log(req);
}, true);

here is log:

22:24:59.598 - Waiting for Server Code tasks..
22:25:18.211 - [2395A82F-4FF0-FDC7-FF21-9840A97D5F00] New task arrived!
{ context:
   { ___jsonclass: 'com.backendless.servercode.RunnerContext',
     deviceType: 'REST',
     userRoles: [ 'NotAuthenticatedUser' ],
     userToken: null,
     prematureResult: null,
     missingProperties: null,
     appId: '4C2A06F3-A0A8-6F00-FF89-DCECE37EB100',
     userRole: [ 'NotAuthenticatedUser' ],
     userId: null,
     eventContext: 'Chapter' },
  item:
   Chapter {
     ___class: 'Chapter',
     ownerId: undefined,
     objectId: undefined,
     created: undefined,
     updated: undefined,
     ChapterName: 'My Test 5',
     ChapterId: 116,
     IsActive: false,
     ___jsonclass: 'Chapter' } }
{ context:
   { ___jsonclass: 'com.backendless.servercode.RunnerContext',
     deviceType: 'REST',
     userRoles: [ 'NotAuthenticatedUser' ],
     userToken: null,
     prematureResult: null,
     missingProperties: null,
     appId: '4C2A06F3-A0A8-6F00-FF89-DCECE37EB100',
     userRole: [ 'NotAuthenticatedUser' ],
     userId: null,
     eventContext: 'Chapter' },
  item:
   Chapter {
     ___class: 'Chapter',
     ownerId: undefined,
     objectId: undefined,
     created: undefined,
     updated: undefined,
     ChapterName: 'MY TEST 5',
     ChapterId: 116,
     IsActive: false,
     ___jsonclass: 'Chapter' } }
22:25:18.323 - [2395A82F-4FF0-FDC7-FF21-9840A97D5F00] Processing finished

As per Log above, it converting to Capitals, but i don’t see the same in record(row) in table. i tried refreshing the table, but still same.

Thanks

I have some success on Users Table but not related to toUpperCase() though. I will move forward with this and will raise my concern if i got stuck again.

Thanks Kate.

Assigning role issue resolved