Increment table ID field from the app

Hi. I am trying to increment the table ID number which is a text field via an app. I managed to get this to work when the app is running. My current trigger looks following:

My table looks like this:
image

I am looking for a way to load the last table entry to the variable in the app as a string → convert the string to integer → increment the integer → convert it back to string → and store it into the same table on the next ID field.

My current triggers work when I start with an empty table and it works until I restart the app.

you can use connector to achieve your goal.

1 Like

hello @Andres, great question!!

as @mcc6025 correctly pointed out, you could use a Connector to the Table API. here’s a quick guide:

  1. create a Connector Function to the Table. for reference, here’s the endpoint I used: /records?limit=1&sortBy=_sequenceNumber&sortDir=desc. as you can see it will always output the largest ID in the Table:


  2. you can then Run the Connector Function from your app and simply increment the max value by 1:

  3. result:

at this point, you can create a new Table Record with that ID (7 in this example).

does that make sense?? let us know!!

I added an extra field to the table to save the incremented integer to the first record when done adding a new record. Then added a “load record” trigger to pull the last ID saved to the table when the first step is opened and save it to the integer. That way you can restart the app as many times as needed and it will still pull the last saved ID from the table. I haven’t had the time to add the table API and test but I know the above way works just fine. I’m kind of late to the party here but let me know if I can help out!

1 Like

when I developed my first tulip app, I once used this way you mentioned
yes, the way works well.

Thanks, I got it solved with Table API.

Hello All,

I think this topic is great to continue working on and I want to summarize here for future reference what is possible now with Queries and Aggregations (without connectors)
For example if someone wants an id such as : Text-{year 2 digits}-{sequential number per year}, I will share a way to do so :

  1. Prepare your table and add a year field for easy queries :
    image

  2. Create query per year :

  3. Create aggregation (count) :

  4. Load query and aggregation in your app (+ create a record placeholder it will be useful) :
    image

  5. Format the current date as needed when app is started using Format_Date_TZ :

  6. You have everything for your id (if you want to start from 1 and not 0 you will need one more data manipulation to increment the value from table aggregation) :

Results :

1 Like

This will create equal Id (based on filtered count value) if record - not last - is deleted.

1 Like

you are right. but I still thanks to pte for his sharing.
in my opinion, hope tulip provides the cursor operation, such as movetolast, then we can load the last record, and get the ID of last record, generate the unique new ID by expression.

1 Like