Hi all! I’ve got a script that prompts the user to select a draft from among a selection of drafts (filtered by tag), and then shows the window a second time to select a draft among another selection of drafts (filtered by a different set of tags).
I have it set up so that if the user presses “Cancel” in the first selection window, the script responds that the user didn’t choose a first draft and then it ends. But, for the second selection window, if the user presses “Cancel,” the script doesn’t end at that part — it seems to still have the first draft in memory as a default if the user doesn’t choose the second draft. We can see this both because, if the user doesn’t choose a second draft, the script will show the first draft in an alert box, and also because if the user doesn’t choose a second script, Drafts reflects that the UUID of the first selection and the second non-selection are the same — again suggesting that Drafts in some way has the first selection in memory as the default value of the second selection.
Highly, highly probable that there’s some user error here, but can anyone discern what’s happening in this script to cause this issue?
function combineDrafts() {
const draftOne = selectDraft({
tagFilter: "tag1, tag2",
requireAllTags: true,
errorMessage: "Draft one not selected.",
});
if (!draftOne) return false;
alert(draftOne.content)
const draftTwo = selectDraft({
tagFilter: "tag1, !tag2",
requireAllTags: true,
errorMessage: "Draft two not selected.", // We never seem to see this error message
});
if (!draftTwo) return false;
alert(draftTwo.content)
if (draftOne.uuid === draftTwo.uuid) {
alert("Draft one and draft two cannot be the same.");
return false;
}
function selectDraft({ tagFilter, requireAllTags = false, errorMessage }) {
const workspace = Workspace.create();
workspace.tagFilter = tagFilter;
workspace.tagFilterRequireAll = requireAllTags;
const selectedDraft = app.selectDraft(workspace);
if (!selectedDraft) {
alert(errorMessage);
}
return selectedDraft;
}
let d = new Draft();
d.content = `Draft One:\n${draftOne.content}\nDraft Two:\n${draftTwo.content}`
d.addTag("tag1, tag2");
d.update();
alert("New draft created!")
return true
}
if (!combineDrafts()) context.fail()
Thanks in advance for your feedback!