Using owner Id to store data in account

Hello,
We are trying to devolp our app so that when you are logged into your account, if you click a button it will set your data to a number up to five, In order though. E.g: You press the button it shows a message 1. You click it again 2 so on and so forth until it reaches 5. Then it will show a differnt message showing that you have reached your limit and reset back to 1. This needs to be possible not just on that device but if you are signed into any acount from anywere. We thought we could do this with the owner Id then incript it so get the 1’s 2’s ect. The only problem is we can’t figure out how to do that.
This is what we have done so far.
image

Best Regards,
Pocket Perks Devolment team :slight_smile:

Hi Tyler,

What if the same user logs into the app from two separate devices (or browsers) at the same time? How should the counting work in that case?

Regards,
Mark

Hi Mark,
Yes it would be ideal if the counting would just continue on, no matter what device.

Thanks

Hi Tyler,

I guess I am confused by the following requirement:

At first, I thought you could persist the current “click number” in the Users table (or a related table by linking to the current user record). However, when you say:

Does this mean that if a user is logged in on multiple devices, they should see the same number everywhere, or should each device have its own sequence?

Regards,
Mark

Ok,
Sorry for the confusion.
Yes it means that if a user is logged in on multipul devices they should see the same number

Thanks

Thank you for the clarification. A solution may look like this:

  1. Every time you change the number, persist it in the database. It can be a property in the Users table - on the UI you can get the current user and then update a property for the current user by performing an update using user’s objectId.
  2. To enable synchronization across multiple devices, use Real-Time Database feature to listen for the updates of the user’s record in the Users table. When an update described in the step above happens, all other clients would receive an event about the change. The docs for the RT database are here: Conditional Delivery of Updated Objects - Backendless SDK for JavaScript API Documentation

Regards,
Mark

Hi Mark,
Sorry to be a pain, but as I am fairly new at this could you dumb it down, just a little please.

Thanks

Sure. Do you know how to update objects in the database?

I think so…
Something like this:

Thanks

Do you have a column in the Users table which will contain the current number for the users? If not, please create one.

Connect a new object to the object connector of the Upsert... block. That object should have two properties: objectId and the one that will contain the current number.

The objectId property will have the objectId value of the current user (you will need to use the “get property of” block to get that.

Please make these changes and share what you got.

Hi,
I am just a bit confused. By connect a new object do you mean this block:
image
Or is it a differnt block

Yes, that’s the one.

Ok:
Here you are


I think this is right

Thanks

No, you do not need to use Get Object By Id at all.

The object connector in the Upsert... block needs to get a new object, which you create with the Create Object block.

Instead of Get Current User Token, you should use the Get current user block:
UI Builder - default - ConsoleDemo - Backendless 2024-10-24 17-26-41

Is the new column called Points ? Did you define it in the Users table?

Ok I fixed that, and yes the new colum is called points.

Your Codeless logic shows Points, if the column is called points, make sure to change it, it must match.

Could you show what the codeless logic looks like now?

I’m not compleatly sure what you mean, but I think is something like this:

I am talking about this:

points and Points are not the same.

if you named your column points, you need to reference it using the same capitalization.

That connector is where you need to put the current value. When the button is clicked, and you increment (or reset) the value, use this logic to update the record in the database.

Test it out, and when it works, we can proceed to the real-time database part.

Yes I did points like Points.
I’ve tried a few ways, but can’t figure it out, what should I attach to the points conector?

The number that you were describing here: