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:
- 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.
- 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.
- Pass all of the long IDs from the formula back down to the child records using a rollup property from the parent
- Since the long IDs are in sequential order, use regex to strip off any characters in the string that fall after the long ID.
- 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