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:

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

* Once we can see them, it’s too late
:ROAM_REFS: @Aaronson2021OnceWeCan
:NOTER_DOCUMENT: ~/Zotero/storage/MSBKIDU3/Aaronson2021OnceWeCan.pdf
:ID: 70650C2F-B388-4EB9-B7EB-C3D3476A9E6C

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.

#+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."
    (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