Listener only works once

One of my listeners stops working after I run some Custom Code within it.

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?

Hello @JohnP

Could you try to wrap your Custom Code in try/catch and handle an error? Also, please provide the app id, container, and page name where it happens.

Regards, Dima

hi @Dima_Vak ,

app id: 0B19E846-DB30-EEE9-FF37-00EF8C3F3900
container: default
page: WaitingRoom

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”.

I tried wrapping the whole of the Custom Code in

try {
} catch (e) {
  console.log(`Error from tryToAcceptInvites: ${e}`)

but did not see any console message.

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.

1 Like

hi @Dima_Vak ,

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”:

  1. 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
  1. Press button “Create Invite”. You will see the console print:
Creating new invite:


~~~ Invites Listener ~~~
1 invite(s) created.
1 invite(s) created FOR this user.

showing that the invite was created then the listener triggered. Then,

  1. 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.

Hello @JohnP

I think you shouldn’t initApp again in your customCode
It has been already initialized by ui-builder


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.