Use scripting to select the draft which has oldest ‘modified’ date in inbox?

Does anyone know if it is possible to use an action script in Drafts to automatically select the draft which has the oldest ‘modified’ date in the inbox?

My scenario is that after archiving a draft, I would like to automatically select the next ‘oldest’ draft (by modification date), and work through the drafts from oldest to newest.

Take a look at the Draft.query() function. It can sort by modified date, and you can specify the order. Populate the query parameters to search the inbox too, and you’ll get an array of Drafts with the first element as the next draft you want. You then can load that in using the editor.load() function.

Based on that, try this:

editor.load(Draft.query("", "inbox", [], [], "modified", false, false)[0]);

Thanks Stephen, that worked perfectly.

Best wishes,

Andy