Help with incrementing a numeric value

Probably very basic, but I’m a beginner so please bear with me. I tried search but all of the answers I could see went right over my head.

I have a Data Type called “Clients” with Fields “Unique ID”, “Client Name”, “Client email” etc. These are displayed in a Repeating Group, next to some input fields and an “Add New” button, so new clients can be added. This is working great so far, except I need the Unique ID number to auto-increment by one every time the Add New button gets clicked.

The tutorial “Reddit Style Upvote City” isn’t quite what I need, in fact it’s probably confused me more. I would be very grateful if anyone could make a quick GIF or YouTube video on this.

When a client is added, you create a new thing, type of thing Clients, Unique ID = Do A Search For Clients:count + 1

2 Likes

Thank you very much for the fast reply :grinning:

1 Like

If you are adding the clients and all clients are shown in the repeating group, you could eliminate the need for do a search of the database which could slow down the app. For example if you have a user who has a list of clients, which is in the database storing all clients of all users, that list could be long and take time to search through…it also wouldn’t increment correctly on the user who is viewing their list of clients and adding new clients to their list.

Instead of using the do a search for you can use the repeating groups list of clients :count+1

This way you are not incrementing based on the entire list of all clients of all users, instead just incrementing for that particular users clients list.

Any time you can find a way to eliminate a need for a search of the database it is a good thing. Using other elements data as datasources can help with that often.

If however, you want to increment on the entire list of all clients of all users, the solution provided earlier obviously works.

But caution the use of an ID that auto increments, if it is for the purposes of tracking the total number of clients the user has added, don’t do a ID, use a sort number or something else…keep the ID as a unique or randomly generated string for the ID to be able to be sure you don’t end up creating things with the same ID

Hello Boston85719, thank you for your reply. The reason I need an ID Number is because I am cross-referencing another table (actually more than one) and if I change the client name then it will break the connection to the other tables, and if I use an ID number instead, the client name can change and the table relationship will stay constant.

For example, Company B places many orders with us. User notices a spelling mistake in Company B’s name, and corrects it. The order table is sorted by Client ID Number instead of Client Name.

I am assuming you are using related tables correctly and the order table has a data field that is related to the client data type…if so, it wouldn’t matter what gets changed on the client data type, the relations to other data types will always remain the same.

Data type 1 = Client
data field = name
data field = id
data field = order_list ( related to data type orders )

Data type 2 = Orders
data field = client ( related to data type client )
data field = products list ( this would be related to the data type products…)

In this brief example, anything that gets changed in the clients data type does not affect the orders data field of client recognizing the relation.

What would change as you point out is if you are sorting that order data table by client name and the name changes from Alphabet Company to Alphanumeric Company, then they may end up in a different position in the list, but all the data and connections remain the same.

If you are really just trying to get it so that there is some consistency in the way an orders data table would be sorted based on the clients details, then use a sort number ( very helpful besides for sorting things in an order, but also matching to repeating groups current cells index which is a number ).

Using the sort number is simply and straight forward in terms of getting them synced…the problem you will always encounter is when a client leaves, and the details are deleted and they had a sort order of “4” or and ID number of “000000004” all other clients that come after will not automatically get changed from “5” to “4”…you’d need to set things up to make that happen.

In regards to sorting things on an order table, you may want to think about the user experience. I don’t know what your use case is for the app you are building, but whether it is for an in-house application or one where you will try to get paying customers, the users will want more control over how they sort.

Some users may want to sort by data of the order, or the amount of the order, or perhaps sorting based on company name…I don’t think many users will be too concerned with sorting by the order in which the client “signed up” or was “created”.