Append to file not working as an ‘include action’

I’m guessing this is a simple fix.

Overall Goal:

  1. Combine a list of drafts based on tag & Create a New Draft with combined drafts, adding a Title;
  2. Take this new draft and append it to an existing text file.

I have both actions working just fine, but when I try to combine both actions into a single action, the 2nd one no longer works…

In my first attempt, I used “include action”… After that, I tried to adding “find/queue action” in my script.

I’m guessing there’s something about how that combined draft is being loaded into the editor that doesn’t allow it to be properly passed onto to the ‘append to file’ action?

Difficult to guess the cause for that. Maybe you can share your actions :wink:

1 Like

I suspect what you have set up it will be operating on whatever your original draft is. I also suspect that it may often be blank in which case it would look like the second action does nothing at all.

If you are using a script to combine the content into a new draft, you could either write the file append directly from the script, or set a custom template tag for the resulting content and the use that rather than “[[draft]]” in the subsequent file action step. But regardless, I would look at combining rather than including or queuing a second action.

1 Like

Ah yes, that might be helpful… This is the first step:


let tag = "j entry";
let d = Draft.query("","archive",[tag],[],"created");
if(d.length > 0)
{
  let newDraft = new Draft();
  newDraft.content = ("## " + draft.processTemplate("[[date| %Y-%m-%d]]" + "\n"));
  
  for(cd of d){
    newDraft.content += "\n" + cd.content
  }
  
  newDraft.update()
  editor.load(newDraft);
} 
else app.displayErrorMessage("No Journal Entries Today");


And this is the 2nd step:

Looks like I was correct and you are using the original draft content.

The simplest solution for you is probably to set the custom tags as described above.

e.g. add the following after newDraft.update():

draft.setTemplateTag("combined", newDraft.content);

Then change [[draft]] to [[combined]] in the file action’s template.

I think that should resolve it.

2 Likes

Nice, that’s solved it! Starting to understand just how useful the template tags are.