Action causing draft to disappear

Hi,

I have a special draft called “Kochplan,” where I collect recipes I want to cook. Once I’ve cooked a recipe, I mark it as done. I have an action that deletes checked-off entries:

let kochplan = Draft.queryByTitle("Kochplan:")[0];
kochplan.content = draft.content.replace(/^.*@done\n?/gm, '');
kochplan.update();

The action works, but if you run it without having the Kochplan draft open in the editor, the Kochplan-draft disappears completely. You can’t find it anymore, not even among the deleted drafts. I see that the action is pretty poor, but I checked that there is exactly one Kochplan-Draft and that it contains undone items. Am I missing something here?

You want the second line to be:

kochplan.content = kochplan.content.replace(/^.*@done\n?/gm, '');

The draft global variable always points to the draft currently loaded in the editor…so your version was replacing the content of the kochplan draft with a value from the (presumably empty when you were testing) draft in the editor.

Thank you very much for your support! I think, I have to update some of my actions (I made a whole set of actions for organizing my home cooking)…