# How to auto-generate org-ID following org-roam-find-file(-immediate)?

**URL:** <https://org-roam.discourse.group/t/how-to-auto-generate-org-id-following-org-roam-find-file-immediate/1412>\
**Category:** Requests\
**Created:** [March 28, 2021, 5:57pm UTC](https://org-roam.discourse.group/t/how-to-auto-generate-org-id-following-org-roam-find-file-immediate/1412 "2021-03-28T17:57:36Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [March 28, 2021, 8:22pm UTC](https://org-roam.discourse.group/t/how-to-auto-generate-org-id-following-org-roam-find-file-immediate/1412/3 "2021-03-28T20:22:52Z")

</div>

I use my own time stamp (yyyy-mm-ddThhmmss) for ID. I don’t think using a custom way to generate an ID “break[s] how org-id keeps track of IDs and their file location”. But you are right in that this way does not get the generated ID stored in `org-id-locations-file`.

[I recently learned](https://org-roam.discourse.group/t/org-roam-major-redesign/1198/64) that you can run `org-id-update-id-locations` with a filename as an argument to get `org-id-locations-file` updated. The command accepts a list of filenames, so you need to do something like `(org-id-update-id-locations '("path/to/file.org"))`.

Alternative to a custom ID generation, you can use `%(sexp)` in org-capture and org-roam-capture, so you could add `%(org-id-new)` in the `:head` property of the capture template; however, `org-id-new` does not seem to call a function to update the id locations, so in any case you’d need to call `(org-id-update-id-locations)` separately (manually, or in some hook).

Perhaps others have better ideas.

**Edit:** It looks like V2’s “capture” (via `org-roam-node-insert`) does seem to add a property drawer with an ID automatically generated… I don’t know how it is done technically, if someone can find it out, you could probably copy the same way in V1.

**Edit 2:** OK… I am answering my own question.  
I am not sure anymore if this is V2 only, but it adds a function to `org-capture-prepare-finalize-hook`; it gets run in the capture process after `C-c C-c` and the new file’s buffer gets presented for you. In this hook, function `org-roam-capture--install-finalize` is called. It kinda does something to add another function. This function generates the property and ID ([source](https://github.com/org-roam/org-roam/blob/v2/org-roam-capture.el#L269)). I think that this “something” is to ensure that this function is called only once for the file generation, but not sure as the hook gets removed.

It looks to be a little too involved for a simple copy and paste into V1 (it might be easy, but I don’t know).

---

_[View the full topic](https://org-roam.discourse.group/t/how-to-auto-generate-org-id-following-org-roam-find-file-immediate/1412)._
