OK, got it. I’d read this at first as being a manual multi-select and process, but I see it is now filtering automatically. But the good news is that yes, this is possible.
Keeping with the approach Andreas has used, you can do this by adding two lines.
I added the first after the remove _watch_tag setting, but you could place it in any number of places in the constraint definition. It is a setting to tell the script to archive drafts it is merging.
remove_watch_tag : true,
archive: true,
max_lines : 5,
Next we want to use that setting. I’ve added this in after the merge tag is added.
draft_candidate.addTag(p_constraints.merged_tag);
draft_candidate.isArchived = p_constraints.archive;
draft_candidate.removeTag(p_constraints.watch_tag);
Here we’re telling the script to update the current draft to set the archival attribute to whatever was set in the constraints.
With the changes above, a little bit of reformatting, switching vars
to lets
(functionally no change, but some good practice to help avoid coding issues), applying your updates, and correcting a variable typo, the revised code might look a bit like this:
// shopping list: finding and merging shopping lists
//TODO: remove watch tag
// ignore processed notes
const constraints =
{
tag_master: "shopping_master",
title_master: "# Shopping",
tag_watch: "watch",
merged_tag: "shopping_merged",
dismissed_tag: "shopping_dismissed",
remove_watch_tag: true,
archive: true,
max_lines: 5,
max_line_length: 42,
look_in: "inbox" // archive, flagged, trash, all
}
function get_items(p_constraints)
{
let match_list = "";
let data_list = Draft.query("", p_constraints.look_in, [p_constraints.tag_watch], [p_constraints.merged_tag, p_constraints.dismissed_tag]);
for (let index in data_list)
{
let draft_candidate = data_list[index];
let content_lines = draft_candidate.lines
let max_line_length = 0;
for (let line_index in content_lines)
{
let active_length = content_lines[line_index].length;
if (max_line_length < active_length) max_line_length = active_length;
}
if (content_lines.length < p_constraints.max_lines && max_line_length < p_constraints.max_line_length)
{
draft_candidate.addTag(p_constraints.merged_tag);
draft_candidate.isArchived = p_constraints.archive;
draft_candidate.removeTag(p_constraints.watch_tag);
for (let line_index in content_lines)
{
let active_item = content_lines[line_index];
if (active_item.length > 0) match_list += content_lines[line_index] + "\n";
}
}
else
{
draft_candidate.addTag(p_constraints.dismissed_tag);
draft_candidate.removeTag(p_constraints.watch_tag);
}
draft_candidate.update();
}
return match_list;
}
let items = get_items(constraints);
// put this into the shopping list draft
let shopping_list = Draft.query("", "all", [constraints.tag_master])[0];
if (shopping_list == null)
{
shopping_list = new Draft();
shopping_list.addTag(constraints.tag_master);
shopping_list.content = constraints.title_master;
}
shopping_list.append(items);
shopping_list.update();