Message:

Subscribe rss
Blog categories
All | Backendless features
How to Use Backendless Counters to Create a Unique ID for Objects in a Table
March 12, 2019 by Sergey Kukurudzyak

Creating unique IDs using Backendless countersFor each entry in a given table, Backendless creates a unique objectId  property – this is a UUID. In some cases, you may want to have a unique ID based on a whole number. To do this, we will use Backendless Atomic Counters (you can read the documentation about Atomic Counters here). In this article, we will use JavaScript business logic to create a handler that will add a unique value before creating the object. You can then store that value in your table to provide the ID you’re looking for.

We’re going to take a step-by-step approach to this example.

  1. Create table with the name Person .
  2. Create a column with the name id  and the Unique Value  and Not Null  constraints.
    Create column in a Backendless table
  3. Add an event handler by visiting the Custom Business Logic section of the console.Add custom business logic event handler
  4. Change the code to the following:

  5. To check that we did it right, go to Data -> Person table -> Rest Console add a record to the table:Add a record to the table using REST console

That’s all it takes to add a unique, incremental ID to each object in your table. Happy coding!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+