Auto-Increment Table Row IDs

Update 05/19/2023 – I am happy to report that this hack is now obsolete! Read the reason why here.

In the absence of a native Notion function to auto-increment record IDs within a database, here is a solution (hack) that may work for your needs.

  • Requires a child database with a relationship to a parent database (in the example I’m creating new entries in the child database from a filtered view so the parent is automatically linked)

How it works:

  1. Create a long ID using Notion’s id() function, and roll this up to the parent. The rollup will contain a list of long IDs for all of the children records that are related to the parent record.
  2. On the parent record, copy the list of child IDs into a new property using a formula. This formats the IDs into a long string with each ID separated by a comma. We need this new property for another rollup, since Notion doesn’t currently allow rollups of a rollup.
  3. Pass all of the long IDs from the formula back down to the child records using a rollup property from the parent
  4. Since the long IDs are in sequential order, use regex to strip off any characters in the string that fall after the long ID.
  5. Then, replace all but “,” characters and count how many there are. Add 1 to this number and this is the auto-assigned ID.
length(replaceAll(replaceAll(replaceAll(prop("Created IDs"), format(prop("Long ID")), "T"), "[^T]*$", ""), "[^,]", "")) + 1

Tip: If you want to start with a higher number than “1”, edit the ID property and change the “+ 1” to the starting number of your choice.

It is worth noting that this solution becomes slow if you implement this on a database that contains a large number of records. Please keep this in mind before deploying this as a solution for your auto-numbering needs.

Before trying to recreate this solution from scratch, I highly recommend duplicating the demo template below to see the relations, rollups, and formulas in action. 👍🏻

Duplicate Notion template

Share:
TwitterFacebookLinkedInPinterestGoogle+

Don't go solo. Navigate all the complexities of life with your Sidekick. Now available

X
Get in Touch
close slider

    Get in Touch

    Have a question or comment? Don't hesitate to reach out!

     

    Please note that I do not respond to cold outreach, requests for free stuff, or anything else that I deem sketchy or scammy