Increase ID only if exists

Good morning, I need help with the following problem that I don’t know how to solve. I am making an order manager and these orders are sent to an external program through the API.
I have a table with products that comes from that external program and another with the orders that I extract from a csv that the supplier sends me.
The problem comes when I want to create an order and send it and there are products that do not yet exist in the product database, so first I have to create these products and then place the order by sending the id of these future products (this id the external program generates it in a consecutive way), I could wait for the products to be created, the api to update and tell me the ID of this, but that can take up to an hour, so I have to work with the id that is going to be create.
What occurred to me is to have a column called temporary id, here if the product exists it puts its id, but if it doesn’t exist it has to put the last id that exists in products +1. With the first one I can do it but then I don’t know how to increment that id + 1 with all the products that do not exist in the product database. Any ideas?,
I have created a doc simulating what I need and the idtemp does not have formulas, I have only written what should happen. thank you so much


I’ve tried this. Since I can’t create products in the products table directly from Coda (as these are created from the external program via API), I’ve created a temporary products table. Products without an ID are created and assigned a temporary ID using the max()+1 formula. However, I’m not sure if this is the best way to do it, and I’m encountering two errors: gaps in the ID sequence (they’re not consecutive) and some products are assigned a later ID when they should be in the order they appear in the list, as otherwise, the ID won’t match with the external program later. Any ideas? Thank you.

Hey @exeinformatica_microsshop! The workaround you’ve found is the best solution that comes to mind, but, we’ll leave this post open for any other Community members to chime in :smile:

1 Like

Not quite sure how to handle incremental IDs in this scenario. What if you used a separate lookup table to manage the temporary IDs?

Hi Juan Carlos

The previous example is a little bit strange, because the increments was not needed all the time.

Here is an example of a document sequence, where you need a unique and complete sequence of document numbers:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.