I have a script below that extracts the draft title and date for drafts tagged “published”. The result is placed in the current draft.
How do I get the result placed into a brand new draft? Currently, I have to remember to manually create a new draft before running the action.
// Generate draft list for "published" tag
var blogDrafts = Draft.query("", "inbox", ["published"]);
for (var i=0; i<blogDrafts.length; i++) {
t = blogDrafts[i].title;
d = blogDrafts[i].createdAt.toString('yyyy-MM-dd');
draft.content += t + "\n" + d + "\n\n";
}
// Generate draft list for "published" tag
var blogDrafts = Draft.query("", "inbox", ["published"]);
var newDraft = new Draft()
let newDraftsContent = ""
for (var i=0; i<blogDrafts.length; i++) {
t = blogDrafts[i].title;
d = blogDrafts[i].createdAt.toString('yyyy-MM-dd');
newDraftsContent += t + "\n" + d + "\n\n";
}
newDraft.content = newDraftsContent
editor.load(newDraft)
you used „draft“ in your script, which always is the current active loaded Draft in the editor when you start an action - just to explain why it didn’t work