Problem
One of my listeners stops working after I run some Custom Code within it.
Details
I add an “RT Data Create” Listener to a table called “Invites”. It listens for invites created for the user. After performing a few small generic actions, it calls some Custom Code (JS) which runs a Transaction called “tryToAcceptInvites”. Basically this code tries to accept one of the invites on the user’s behalf, as long as this user and the other user haven’t already accepted another invite.
The first time an invite is created for the user, the Listener successfully fires. But the second time and all subsequent times, it doesn’t fire. But I figured out that if I disable the Custom Code “tryToAcceptInvites” within it, it correctly continues to fire.
So something in my Custom Code is killing the Listener. Does this ring a bell for anyone experienced with Backendless? What could make a Listener just “die” like this?
The custom code is the last line, tryToAcceptInvites, within the RT Data Create Listener to “Invites” table, inside “On Record Selected” of “Db Table Online”.
Unfortunately, I couldn’t even access and fire this custom code in preview.
Please, create a simple example on a new page with the minimum of code where the issue is reproduced and describe steps on how we could reproduce it by ourselves.
I did my best to create a minimal reproduction of the issue on a new page, but I could not reproduce it. On the new page I created to do this, the listener stays alive.
To see the listener die on page “Waiting Room” of container “default”:
Go down to the DB Table and select user “John”. You should see the console print:
User is: John (6F2A5B45-0EF4-42CC-AB8F-A9A9BAD5AA4F)
Listen for newly created Invites for or with user 6F2A5B45-0EF4-42CC-AB8F-A9A9BAD5AA4F
Press button “Create Invite”. You will see the console print:
Creating new invite:
then
~~~ Invites Listener ~~~
1 invite(s) created.
1 invite(s) created FOR this user.
showing that the invite was created then the listener triggered. Then,
Press “Create Invite” again. You should see
Creating new invite
in the console again but this time, you don’t see
~~~ Invites Listener ~~~
The listener has died and will never fire again until I re-select the record or refresh the page.
It looks like fixing this keeps the listener alive. Thankyou Viktor.
TLDR for anyone reading this:
You don’t need to load the Backendless module and initialize your app in every piece of Custom Code you write in the UI Builder.