Skip to content

Instantly share code, notes, and snippets.

@ggondim
Last active February 9, 2022 22:52
Show Gist options
  • Save ggondim/2db4b839af011f6412ffead49ea5e5e3 to your computer and use it in GitHub Desktop.
Save ggondim/2db4b839af011f6412ffead49ea5e5e3 to your computer and use it in GitHub Desktop.
Notion unique ID formula
format(toNumber(formatDate(prop("_criacao"), "YY")) - 20) + formatDate(prop("_criacao"), "W") + if(slice(format(prop("_autor")), toNumber(slice(format(toNumber(formatDate(prop("_criacao"), "X"))), 8, 9)), toNumber(slice(format(toNumber(formatDate(prop("_criacao"), "X"))), 8, 9)) + 1) + slice(id(), 25, 26) == " ", "x", slice(format(prop("_autor")), toNumber(slice(format(toNumber(formatDate(prop("_criacao"), "X"))), 8, 9)), toNumber(slice(format(toNumber(formatDate(prop("_criacao"), "X"))), 8, 9)) + 1) + slice(id(), 25, 26)) + slice(format(toNumber(formatDate(prop("_criacao"), "X"))), 9, 10) + slice(prop("_title"), 2, 3)

This is an algorithm to generate short IDs for Notion pages, based on:

  • year unit digit
  • week number
  • page author's Nth character where N is the 8th digit of created timestamp, replacing spaces by "x"
  • 25th character of Notion random id
  • 9th digit of created timestamp
  • 3rd character of page title

The generated ID is expected to have 6-7 characters lenght, including alphanumeric, case-sensitive, diacritics-sensitive, characters.

How to use

  1. Create a formula property
  2. Paste the Gist formula in Notion, replacing:
  • _criacao by the name of "Created time" property
  • _autor by the name of "Created by" property
  • _title by the name of "Title" property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment