Using the contents of a draft found through a query

Hi there,

Hoping someone can help me with this. For reasons, I am working on a script that gets the second line of a pre-set draft that contains a UUID (on the second line), then use the UUID in that draft to find another draft by UUID.

Here’s what I’ve got so far:

let reference = Draft.queryByTitle("thingsforthingsreference95178954651d");

let projectfile = reference.content.split("\n");

let d = Draft.find(projectfile[1]);

The error I’m getting is:

Script Error: TypeError: undefined is not an object (evaluating ‘reference.content.split’)
Line number: 3, Column 36

queryByTitle returns an array of drafts. It may find more than one.

If you want to reliably find a specific draft, it’s better to use find with the UUID. If you really want to fuzzy search by title, and trust you will not have a naming conflict, than you just need to use the first element of the array of drafts returned, like:

let reference = Draft.queryByTitle("thingsforthingsreference95178954651d")[0];

Argh, arrays get me again. Thanks, it works now!

I’m actually doing an experiment to see if I can make my “Things for Things” action group configurable without having someone go into the action’s script to add a UUID. I’ve added an action that prompts the user to pick the draft where their projects list is saved, then saves that value to a special reference draft (titled the above) that contains the UUID of the draft they specific on line 2. Then both actions that reference the projects list reference this very special draft to get the proper UUID. I picked a very specific draft name with some random numbers at the end in hope it will always be unique.

This may very well be a house of cards, and probably the average drafts user knows how to read a script enough to change the UUID value, but it was really bugging me that people had to do that first.

I would make a couple of suggestions:

  • Consider simply putting the configurable variable is a separate script step at the beginning of the action with instructions for configuration. Example action setup this way.
  • Alternately, consider using a Credential object to store the configurable options, that do not clutter up the draft list.

Those are great suggestions, thanks!

For the Credential object, is there any way to pass over the result of a prompt to select a draft into it? Or can you only prompt specifically for a text entry credential? I’m hoping that a user of my action will never need to know what a “UUID” is.

Here is my work in progress action step to get an idea of what I’m looking to do:

https://actions.getdrafts.com/a/1cH