How to prevent `org-roam-capture` from adding ID property?

The org roam capture template I rely upon to capture bibliographic notes creates a new file with an org heading, and places all relevant PROPERTIES in a drawer right below that heading, including an ID property. However, org-roam-capture appears to be set so that it always creates a file-level ID property, which results in an annoying and unnecessary proliferation of IDs. Here’s how a captured bibliographic note looks:

:PROPERTIES:
:ID: 1DFCA536-6F58-4A8B-9E08-E7E580C706AD
:END:
#+title: Once we can see them, it’s too late

* Once we can see them, it’s too late
:PROPERTIES:
:ROAM_REFS: @Aaronson2021OnceWeCan
:URL: https://www.scottaaronson.com/blog/?p=5253
:NOTER_DOCUMENT: ~/Zotero/storage/MSBKIDU3/Aaronson2021OnceWeCan.pdf
:NOTER_PAGE: 
:ID: 70650C2F-B388-4EB9-B7EB-C3D3476A9E6C
:END:

As far as I can tell, there is no user option to change this behavior. The best I was able to do, with my extremely limited Elisp skills, is to tweak the org-roam-capture- function so that it does not insert a new ID value. But org-roam-capture still creates a file-level PROPERTIES drawer, with an ID key but no corresponding value, i.e.

:PROPERTIES:
:ID:
:END:
#+title: Once we can see them, it’s too late

I would appreciate any guidance on how to change org-roam-capture- or other relevant functions so as to prevent org-roam-capture from creating this drawer altogether.

(Note that initially org-roam-capture was also inserting a ROAM_REFS property under the file-level drawer, but I solved this by setting org-roam-capture-new-node-hook to nil. See also related discussion here and here)

You can use org without org-roam to capture data which is not a roam node. Org roam requires IDs to identify its nodes. See also the documentation:

An [org-roam] node is any headline or top level file with an ID.

Hi, thanks. Yes, I am aware that org roam requires IDs to identify its nodes—I just don’t want the file itself, as opposed to the headings it contains, to be treated as a node.

Concerning using org-capture rather than org-roam-capture, the capture template is not invoked manually, but is rather triggered when certain at-point actions are selected using the citar, embark and org-roam-bibtex packages. I don’t think this behavior could be easily replicated with an org-capture template.

I have ventured in this domain in the past as well and from what I saw, it would be rather hard to remove this behaviour. You need to either use org-capture or live with the fact that this is the behaviour of org-roam-capture unfortunately.

Instead of setting it to nil, how about adding (appending to the end) a custom function to:

  1. Remove ROAM_REFS property (e.g. org-delete-property "ROAM_REFS)
  2. Check if the point is in the file property drawer, if so delete the ID property; leave it unchanged if point is in a headline (I think the point should be 1 if in the file property drawer, so the check should be trivial)

org-delete-property removes the entire property drawer when deleting the last remaining property, so you could have a clean Org file.

I don’t know how we can add a headline node; how do you do your capture to the headline of a file?

1 Like

I do the following for my Md-roam to avoid Org-roam adding an Org-ID to the top of the file.

My previous suggestion might be simpler to implement. I don’t use headline nodes, so you would need to adjust the code. This adds advice and then uses a hook to clean up the advice – yes, a bit convoluted but this is a technique Org-roam uses in some cases.

Thanks, this works. The function I used:

  (defun ps/org-roam-remove-file-level-properties ()
    "Remove `ROAM_REFS' and `ID' properties from file-level drawer."
    (goto-char
     (point-min))
    (org-delete-property "ID")
    (org-delete-property "ROAM_REFS"))

There may be a more elegant way to do it, but this worked for me!

1 Like

I found this thread when looking for information on how to stop the org-roam-dailies capture to insert an ID property for the week’s heading.

The solution is short but it was not obvious what org functions and hooks would work.

My notes are captured in a ‘week tree’, and by default an ID is created for the day heading such as ‘2024-11-11 Monday’.

I didn’t want these day headings to be included in the org-roam-node-find search results.

(setq org-roam-dailies-capture-templates
      '(("d" "default" entry
         "* %<%H:%M> %?"
         :target (file+datetree "%<%Y-%m>.org" week)
         :tree-type week
         )))
* 2024
** 2024-W45
*** 2024-11-08 Friday
:PROPERTIES:
:ID:       edd396e8-3c46-42b4-9417-a38318eeeeac
:END:
**** 19:00 some notes
**** 19:10 further notes
** 2024-W46
*** 2024-11-11 Monday
:PROPERTIES:
:ID:       52b75ae4-d69a-42d8-9eb4-3edef613d17e
:END:
**** 17:10 notes
**** 17:10 more notes

After some experimentation, the following function and hook worked.

(defun gb/org-roam-dailies-capture-remove-id ()
  "When capturing a dailies note, remove the ID generated at the parent heading, such as '2024-11-11 Monday'."
  (when (org-roam-dailies--daily-note-p)
    (push-mark (point))
    (org-up-heading-safe)
    (org-delete-property "ID")
    (pop-to-mark-command)))

(add-hook 'org-capture-before-finalize-hook #'gb/org-roam-dailies-capture-remove-id)
1 Like