Draft.query(..) filter with logic "and" in tag list

the Draft.query() function just lets us use a list of tags and gives corresponding results when I query something like:
Drafts.query("",“all”,[“templates”,“personal”]
and
Drafts.query("",“all”,[“templates”,“work”]

For me it would be really helpful when the tags could be connected with logic so choose if and / or should be used.

Currently I use the omitTags but for scripting a bigger filter action it would be much easier to use AND :slight_smile:

This can be done by scripting Workspaces. You can create a temporary workspace in script and query it’s drafts, something like:

let ws = Workspace.create();
ws.tagFilter = "template, personal";
ws.tagFilterRequireAll = true; // or false for "or" search
let drafts = ws.query("all");

If you never call update() on the workspace object, it is never saved, just used in the script.

1 Like

This is too simple :slight_smile: thank you
Didnt see the woods for the trees

Hey - is it somehow possible to sort the result of ws.query(“all”)?
the docs just include sort apis for inbox, flagged and archive. if I use all three and then query all, its still mixed up.?

Next update will add methods to script the Workspace all settings. That is an oversight.

You can always sort the array after you get it back, too. Something like:

let drafts = ws.query("all");
drafts.sort((a, b) => a.modifiedAt > b.modifiedAt);

Yes i already did it like this but i thought it Fouls ne much easier, thanks