Unfortunately, that is not a true statement.
Workspaces are built from the following:
- Text search queries.
- Tag filters (including matching any, matching all, options for omissions).
- Start dates.
- End dates.
- The folders for a workspace each have their own settings, and so flagged draft inclusion can also play a part. I think the
Draft.query()
will utilise the default (null workspace) settings for this.
Instead, the Workspace
object has its own equivalent query that does take into account the above.
Here is one way I might build something to do this. I’ve expanded it a little in the function to make it easier to comment and follow.
Let’s start with a simple action to display the title of a draft. I’ve specifically made it an example action that is not purely script-based so that we are forced to call the separate action rather than just bundling it into one set of code. More efficient to code as one I suspect, but this is the more generic case.
Now, let’s create a little function that we can call. We’ll give it the name of the Workspace, we want to use, the name of the folder within that workspace that we want to process, and the name of the Action that we want to use.
function processWorkspaceDrafts(p_strWorkspaceName, p_strFolder, p_strActionName)
{
//Get the action 'object' to be run against each draft
let acToRun = Action.find(p_strActionName);
//Get all of the drafts in the specified folder in the specified workspace
//and then process each of them in turn
let adWorking = Workspace.find(p_strWorkspaceName).query(p_strFolder);
adWorking.forEach(function (draftCurrent)
{
//Queue the action to run against the draft
app.queueAction(acToRun, draftCurrent);
});
//At the end as a final useful bit of information, we'll return the number of drafts processed.
return adWorking.length;
}
To utilise this, create an action with a *Script* step. Add the function above, and then we just need to add an additional line to call it.
For example, if I wanted to run this against my “novel” workspace, but just against the drafts I have in my inbox in that folder, my calling line for the function above might look like this.
processWorkspaceDrafts("novel", "inbox", "Display Title");
If I wanted to get a brief overview on its processing, I could do this.
app.displayInfoMessage("Drafts sent for processing: " + processWorkspaceDrafts("novel", "inbox", "Display Title"));
But do note that this message is displayed after the initial action is run, which is before each of the queued actions is run.
A small rabbit hole on this point
If you wanted to get the information displayed right at the end of all processing, you would need to queue another action to display the information. You would then either need to write it to file for retrieval, store it on the clipboard, or queue that action on the current draft and use a custom template tag to store the value. However, you also need to be aware that in the interim one of the previous queued actions could update the draft and potentially cause issues; but the risks are low.
I hope that’s all easy enough to follow and explains why you shouldn’t just use Draft.query()
, and a way that I think would work generically. At least it did in my testing so far