# Refile to roam from gtd inbox

**URL:** <https://org-roam.discourse.group/t/refile-to-roam-from-gtd-inbox/847>\
**Category:** How To\
**Created:** [October 10, 2020, 4:48pm UTC](https://org-roam.discourse.group/t/refile-to-roam-from-gtd-inbox/847 "2020-10-10T16:48:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stfl](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@stfl](https://org-roam.discourse.group/u/stfl)\
**Post date:** [October 10, 2020, 4:48pm UTC](https://org-roam.discourse.group/t/refile-to-roam-from-gtd-inbox/847/1 "2020-10-10T16:48:27Z")

</div>

I am currently setting up a GTD workflow and I want to use roam as my knowledge base.  
The idea is to capture everything into my inbox and in case it should be kept for reference I want to refile it into roam.

From what I have seen most people capture directly into roam.  
What would be the best practice to refile from a gtd inbox. Or is it strictly advised to separate TODO inbox from reference inbox?

I am trying to write a function to refile a tree from my regular [inbox.org](http://inbox.org) to my roam directory.  
It should either refile the tree into an already existing file or create a new file from the tree.

I am a total noob with elisp. Started writing elisp yesterday. That’s how far I got so far:  
Basically I copied most of the code from org-roam.el \> org-roam-find-file ()

```
;; initial prompt should be the text of the tree
(defun stfl/refile-to-roam2 (&optional initial-prompt)
  (interactive)
  (let* ((completions (org-roam--get-title-path-completions))
         (title-with-tags (org-roam-completion--completing-read "File: " completions :initial-input initial-prompt))
         (res (cdr (assoc title-with-tags completions)))
         (file-path (plist-get res :path)))
    ;; if we have a file-path -> call org-refile
    (if file-path
      (let ((org-refile-targets ((file-path :maxlevel . 4)))) ;; FIXME file-path seems to be the incorrect type
        (call-interactively 'org-refile))
      ;; if we can't find a file call a org-roam-capture
      ;; TODO this does not yet actually refile the subtree
      (let ((org-roam-capture--info `((title . ,title-with-tags)
                                      (slug . ,(funcall org-roam-title-to-slug-function title-with-tags))))
            (org-roam-capture--context 'title))
        (setq org-roam-capture-additional-template-props (list :finalize 'find-file))
        (org-roam-capture--capture))
      )))

```

I ran this through the debugger and getting file-path works and is type string.  
org-refile-targets requires some other type?  
The problem is not actually related to roam but org-refile-targets and my elisp noob’ness but I hope someone can direct help me out…

---

<div class="post-metadata">

**Author:** ![telotortium](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@telotortium](https://org-roam.discourse.group/u/telotortium)\
**Post date:** [November 17, 2020, 11:54pm UTC](https://org-roam.discourse.group/t/refile-to-roam-from-gtd-inbox/847/2 "2020-11-17T23:54:26Z")

</div>

I wrote a function to refile existing headlines to new org-roam note files: [Creating an org-roam note from an existing headline](https://org-roam.discourse.group/t/creating-an-org-roam-note-from-an-existing-headline/978)

---

<div class="post-metadata">

**Author:** ![midas](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@midas](https://org-roam.discourse.group/u/midas)\
**Post date:** [August 23, 2021, 8:47pm UTC](https://org-roam.discourse.group/t/refile-to-roam-from-gtd-inbox/847/3 "2021-08-23T20:47:47Z")

</div>

> [@stfl](#):
>
> It should either refile the tree into an already existing file or create a new file from the tree.

If you are refiling to a pre-existing org-roam file, the following might be helpful:

> [@Refile entries/nodes between org files and org-roam notes](https://org-roam.discourse.group/t/refile-entries-nodes-between-org-files-and-org-roam-notes/1484):
>
> For a variety of reasons, I often need to refile nodes/entries between org-roam files and my other org files (e.g., org-agenda-files). I find the following accomplishes this and I am posting in case others have a similar need : (setq myroamfiles (directory-files "~/path/to/my/roam/notes" t "org$")) ;; -------- refile settings ----- (setq org-refile-targets '((org-agenda-files :maxlevel . 5) (myroamfiles :maxlevel . 5))) (setq org-refile-use-outline-path 'file) (setq org-outline-path-…
