Org-roam bibtex & orb-edit-note error

title: Griffith, E. M. et al. 2018: Combining metal and nonmetal isotopic measurements in barite to identify mode of formation
:PROPERTIES:
:ID:
:ROAM_REFS:
:Custom_ID: Griffith2018
:URL: http://www.sciencedirect.com/science/article/pii/S0009254118304789
:AUTHOR: Griffith, E. M., Paytan, A., Wortmann, U. G., Eisenhauer, A., & Scher, H. D.
:title: Combining metal and nonmetal isotopic measurements in barite to identify mode of formation
:year: 2018
:END:
#+startup: latexpreview
- tags ::
- keywords ::

* Notes
:PROPERTIES:
:NOTER_DOCUMENT: 
:END:
:PROPERTIES:
:ID:       2a717ed4-0a19-4980-8796-1e01b0caaee2
:ROAM_REFS: cite:&Griffith2018
:END:

The problem is very obvious - they lack both the ID and ROAM_REFS keys!!!I recommend altering your template file

- tags ::
- keywords :: %^{keywords}

* %^{title}
:PROPERTIES:
:Custom_ID: %^{citekey}
:URL: %^{url}
:AUTHOR: %^{author-or-editor}
:NOTER_DOCUMENT: %^{file}
:NOTER_PAGE:
:END:

Make your template file as backup and try mine and paste the same info after capturing again. The ID and ROAM REF keys should be filled

For examples my capture come out as

:PROPERTIES:
:ID:       20250926T003432.062344
:ROAM_REFS: cite:robinson-1953-produc-funct
:END:
#+title: The production function and the theory of capital

- tags ::
- keywords :: 

* The production function and the theory of capital
:PROPERTIES:
:Custom_ID: robinson-1953-produc-funct
:URL: https://www.jstor.org/stable/2296002
:AUTHOR: Robinson, J.
:NOTER_DOCUMENT: 
:NOTER_PAGE:
:END:

Notice that the :id: field is minimally filled - without it the file is not a node + if the ID is placed inside * Notes then there will be obvious conflict among notes since multiple nodes will have the same name “Notes” this is not alright.

Your template should not be bothered with setting anything above - tags especially anything related to :PROPERTIES: ideally - it is not required for org-noter.

PLUS VERY IMPORTANT. NOTICE HOW :PROPERTIES: of the file is at the TOP and nothing obstructs it - your template obstructs it.

(setq org-roam-capture-templates
      '(("r" "bibliography reference" plain
         (file "~/.emacs.d/org-roam-bibtex-notes-templates.org")
         :target (file+head "references/${citekey}.org"
			    "#+title: ${title}\n"))))

Also give the page a title by changing your capture template - use the file+head instead of simply file.

Apologies for the sluggish reply, but discord kicked me out with a daily message limit error. I tried you suggestions, but unless I overlook the obvious, the result remains the same, i.e., there is no id field. Below are the details. Note, all of this is with the (defun undo-2056/org-roam-capture--setup-target-location () code you sent earlier. If I remove it, I end up with the earlier issue orb-edit-note caught an error during capture: Capture template ‘r’: No node at point

On another note, I noticed that creating a regular org-roam node, now asks for the citekey.

ok, using your template file:

- tags ::
- keywords :: %^{keywords}

* %^{title}
:PROPERTIES:
:Custom_ID: %^{citekey}
:URL: %^{url}
:AUTHOR: %^{author-or-editor}
:NOTER_DOCUMENT: %^{file}
:NOTER_PAGE:
:END:


* Notes
:PROPERTIES:
:NOTER_DOCUMENT: %^{file}
:END:

and

(setq org-roam-capture-templates
      '(("r" "bibliography reference" plain
         (file "~/.emacs.d/org-roam-bibtex-notes-templates.org")
         :target (file+head "references/${citekey}.org"
			    "#+title: ${title}\n"))))

yields the following captured note

- tags ::
- keywords :: 

* Long-Term History of Continental Weathering and Particle
                  Transport To the Sea
:PROPERTIES:
:Custom_ID: canfield-2025-long-term
:URL: {http://dx.doi.org/10.1073/pnas.2507312122}
:AUTHOR: Don E. Canfield, Zhang, S., Wang, R. N. M. a. X., Naemi, A., & Zhang}, C. J. S. a. P.
:NOTER_DOCUMENT: ~/Documents/papers_to_read/canfield-2025-long-term.pdf  ; <== special file keyword: if more than one filename
:NOTER_PAGE:               ;     is available, the user will be prompted to choose
:END:
:PROPERTIES:
:ID:       d06c76a3-66fb-4977-8190-a4713ad12766
:ROAM_REFS: cite:&canfield-2025-long-term
:END:
#+title: Long-Term History of Continental Weathering and Particle
                  Transport To the Sea

using setq removes all your other templates - I just gave an example - you should modify your template collection rather than making this the only template available for all captures.Your results are really erratic - even then an entry like this should be available in the database since it contains the ID and ROAM_REFS key. Forget about capturing just create a file in your org-roam directory and paste the following

:PROPERTIES:
:ID: randomid0
:ROAM_REFS: cite:&helloworld0
:END:
#+title: test


* h1
:PROPERTIES:
:ID: randomid1
:ROAM_REFS: cite:&helloworld1
:END:


Then save this file.

On your terminal - install sqlite3 - then go ~/.emacs.d

[~/.emacs.d] ~> sqlite3 org-roam.db
sqlite> select * from refs where ref like '%helloworld%';

output:
“randomid0”|“helloworld0”|“cite”
“randomid1”|“helloworld1”|“cite”

If this doesnt happen - something else is crooked

The reason they are not showing up is because somehow the template is creating two properties stacked - the second one is just silently ignored

Compare with the above -

I see wrt capture templates (see below)

Adding a file manually works as expected

sqlite> select * from refs where ref like '%helloworld%';
"randomid0"|"helloworld0"|"cite"
"randomid1"|"helloworld1"|"cite"
sqlite> 

strangely enough a note with id is created when I use the default template entry (albeit in the wrong directory), below is the actual template code:

(setq org-roam-capture-templates
      '(("r" "bibliography reference" plain
         (file "~/.emacs.d/org-roam-bibtex-notes-templates.org")
         :target (file+head "references/${citekey}.org"
			    "#+title: ${title}\n"))
	("d" "default" plain "%?"
	 :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
			    "#+startup: latexpreview\n keywords: \n#+title: ${title}\n"
			    )
	 :unnarrowed t)
	)
      )

https://raw.githubusercontent.com/org-roam/org-roam/7ce95a286ba7d0383f2ab16ca4cdbf79901921ff/org-roam-capture.el

This from release 2.3.1 - paste the contents of the file in your Scratch buffer or any emacs-lisp mode buffer then evaluate this buffer M-x eval-buffer - Try the capture again with this older version - something is amiss - the capture is behaving erratically.Please test with this exact template format

- tags ::
- keywords :: %^{keywords}

* %^{title}
:PROPERTIES:
:Custom_ID: %^{citekey}
:URL: %^{url}
:AUTHOR: %^{author-or-editor}
:NOTER_DOCUMENT: %^{file}
:NOTER_PAGE:
:END:

Nothing more - that way we can have congruence in our tests

I think it would work - because we have narrowed down the problem. If that worked then replace the earlier code block with this

(defun undo-2056/org-roam-capture--prepare-buffer ()
  "Prepare the capture buffer for the current Org-roam based capture template.
This function will initialize and setup the capture buffer,
position the point to the current :target (and if necessary,
create it if it doesn't exist), and place the point for further
processing by `org-capture'.

Note: During the capture process this function is run by
`org-capture-set-target-location', as a (function ...) based
capture target."
  (let ((id (cond ((run-hook-with-args-until-success 'org-roam-capture-preface-hook))
                  (t (org-roam-capture--setup-target-location)))))
    (org-roam-capture--adjust-point-for-capture-type)
    (let ((template (org-capture-get :template)))
      (when (stringp template)
        (org-capture-put
         :template
         (org-roam-capture--fill-template template))))
    (org-roam-capture--put :id id)
    (org-roam-capture--put :finalize (or (org-capture-get :finalize)
                                         (org-roam-capture--get :finalize)))))

(defun undo-2056/org-roam-capture--setup-target-location ()
  "Initialize the buffer, and goto the location of the new capture.
Return the ID of the location."
  (let (p new-file-p)
    (pcase (org-roam-capture--get-target)
      (`(file ,path)
       (setq path (org-roam-capture--target-truepath path)
             new-file-p (org-roam-capture--new-file-p path))
       (when new-file-p (org-roam-capture--put :new-file path))
       (set-buffer (org-capture-target-buffer path))
       (widen)
       (setq p (goto-char (point-min))))
      (`(file+olp ,path ,olp)
       (setq path (org-roam-capture--target-truepath path)
             new-file-p (org-roam-capture--new-file-p path))
       (when new-file-p (org-roam-capture--put :new-file path))
       (set-buffer (org-capture-target-buffer path))
       (setq p (point-min))
       (let ((m (org-roam-capture-find-or-create-olp olp)))
         (goto-char m))
       (widen))
      (`(file+head ,path ,head)
       (setq path (org-roam-capture--target-truepath path)
             new-file-p (org-roam-capture--new-file-p path))
       (set-buffer (org-capture-target-buffer path))
       (when new-file-p
         (org-roam-capture--put :new-file path)
         (insert (org-roam-capture--fill-template head 'ensure-newline)))
       (widen)
       (setq p (goto-char (point-min))))
      (`(file+head+olp ,path ,head ,olp)
       (setq path (org-roam-capture--target-truepath path)
             new-file-p (org-roam-capture--new-file-p path))
       (set-buffer (org-capture-target-buffer path))
       (widen)
       (when new-file-p
         (org-roam-capture--put :new-file path)
         (insert (org-roam-capture--fill-template head 'ensure-newline)))
       (setq p (point-min))
       (let ((m (org-roam-capture-find-or-create-olp olp)))
         (goto-char m)))
      (`(file+datetree ,path ,tree-type)
       (setq path (org-roam-capture--target-truepath path))
       (require 'org-datetree)
       (widen)
       (set-buffer (org-capture-target-buffer path))
       (unless (file-exists-p path)
         (org-roam-capture--put :new-file path))
       (funcall
        (pcase tree-type
          (`week #'org-datetree-find-iso-week-create)
          (`month #'org-datetree-find-month-create)
          (_ #'org-datetree-find-date-create))
        (calendar-gregorian-from-absolute
         (cond
          (org-overriding-default-time
           ;; Use the overriding default time.
           (time-to-days org-overriding-default-time))
          ((org-capture-get :default-time)
           (time-to-days (org-capture-get :default-time)))
          ((org-capture-get :time-prompt)
           ;; Prompt for date.  Bind `org-end-time-was-given' so
           ;; that `org-read-date-analyze' handles the time range
           ;; case and returns `prompt-time' with the start value.
           (let* ((org-time-was-given nil)
                  (org-end-time-was-given nil)
                  (prompt-time (org-read-date
                                nil t nil "Date for tree entry:")))
             (org-capture-put
              :default-time
              (if (or org-time-was-given
                      (= (time-to-days prompt-time) (org-today)))
                  prompt-time
                ;; Use 00:00 when no time is given for another
                ;; date than today?
                (apply #'encode-time 0 0
                       org-extend-today-until
                       (cl-cdddr (decode-time prompt-time)))))
             (time-to-days prompt-time)))
          (t
           ;; Current date, possibly corrected for late night
           ;; workers.
           (org-today)))))
       (setq p (point)))
      (`(node ,title-or-id)
       ;; first try to get ID, then try to get title/alias
       (let ((node (or (org-roam-node-from-id title-or-id)
                       (org-roam-node-from-title-or-alias title-or-id)
                       (user-error "No node with title or id \"%s\"" title-or-id))))
         (set-buffer (org-capture-target-buffer (org-roam-node-file node)))
         (goto-char (org-roam-node-point node))
         (setq p (org-roam-node-point node)))))
    ;; Setup `org-id' for the current capture target and return it back to the
    ;; caller.
    (save-excursion
      (goto-char p)
      (if-let ((id (org-entry-get p "ID")))
          (setf (org-roam-node-id org-roam-capture--node) id)
        (org-entry-put p "ID" (org-roam-node-id org-roam-capture--node)))
      (prog1
          (org-id-get)
        (run-hooks 'org-roam-capture-new-node-hook)))))


(advice-add 'org-roam-capture--setup-target-location :override
	    #'undo-2056/org-roam-capture--setup-target-location)

(advice-add 'org-roam-capture--prepare-buffer :override
	    #'undo-2056/org-roam-capture--prepare-buffer)

we just reverse changes to another function - I am pretty sure this will fix the capture error for you

done and done, and now I get

:PROPERTIES:
:ID:       3254684b-331b-4fcd-a645-78976cfb23df
:ROAM_REFS: cite:&canfield-2025-long-term
:END:
#+title: Long-term history of continental weathering and particle transport to the sea
- tags ::
- keywords :: 

* Long-term history of continental weathering and particle transport to the sea
:PROPERTIES:
:Custom_ID: canfield-2025-long-term
:URL: http://dx.doi.org/10.1073/pnas.2507312122
:AUTHOR: Canfield, D. E., Zhang, S., Mitchell, R. N., Wang, X., Naemi, A., Spencer, C. J., & Zhang, P.
:NOTER_DOCUMENT: ~/Documents/papers_to_read/canfield-2025-long-term.pdf  ; <== special file keyword: if more than one filename
:NOTER_PAGE:               ;     is available, the user will be prompted to choose
:END:

re-openeing the note, also works as expected

Great - we have narrowed down the problem - the latest change just broke everything.

You can even drop in that file in place and compile - or you can keep the above code in your init for now - I shouldve noticed that - i somehow just glanced over it. Apologies

no problem. Thanks!

1 Like

see if removing the code with the latest org-roam fixes the problem - today a patch for some fix went online. Probably this problem has been fixed. Test and let know if possible.

I did some limited testing, but appears that I can

  1. create a new non-existing note as expected
  2. that I can revisit that note from the bibtex buffer

Thanks again for helping out!