Prompt to select from list in a draft?

Hi all, relatively new action-creator here. I am trying to create a template for meeting notes and have greatly appreciated all the examples posted in the directory! One thing I’m trying to do that I can’t find an example for is prompt to enter project names from a list, where the list would be maintained in a draft that the action would read.

I can see examples for how to create a Prompt with selection options. But is there any way for the script to read the options from a designated draft (“project list”, say) that could be dynamically updated, rather than having to go into the script and manually update the selection list every time I add a new project?

Greatly appreciate any examples or suggestions!

Scripts can load a draft and read it’s contents, yes. Assuming you have created this draft with your list with one item on each line, you could do the following:

// get the real UUID value from (i) info for your draft with the list
let d = Draft.find("UUID-FOR-DRAFT");
// split the draft into an array of lines...
let list = d.content.split("\n");

// now you can loop over the lines to add to your prompt...
for (let item of list) {
    // add to prompt
}

Hopefully that will get you going in the right direction.

Hi there! I’m trying to do this exact thing and I’m getting totally stuck. I’m sure with better JavaScript acumen, I’d be able to get this, but I just can’t seem to get the script working correctly. Here’s what I’ve got so far based on Greg’s starting suggestion:

// get the real UUID value from (i) info for your draft with the list
let d = Draft.find(“UUID OF MY PROJECT LIST");
// split the draft into an array of lines...
 let list = d.content.split("\n");


 var selections

// now you can loop over the lines to add to your prompt...

 for (let item of list) {
    selections.push(item)
}

 var p = Prompt.create();

 p.title = "Pick a project";
 p.message = "How would you like the task to repeat?"
 p.addSelect("project", "Project", [selections], [], false)
 p.addButton("OK");

 var selection = p.show()

My thinking is that I can populate the list of options through the “selections” variable which is an array that I am pushing the values to via the loop.

When I run the action, I get an error saying that “undefined” is not an object. It looks like that’s the first value that comes out of the draft that I am pointing to, but the first line in that draft definitely has a value.

Any help would really be appreciated!

i would’ve written selections = [].

Two things:

  • var selections = []; will explicitly let JavaScript know you want selections to be an array containing multiple values and the push call will work then.
  • In the addSelect call, you should pass selections, not [selections], since it is already an array…by putting it in the brackets you are creating a new array, with the other array as it’s first and only value.
2 Likes

Success! Thanks so much for your help, it’s now working. Now to figure out how to get the results pasted to the clipboard…

By the way, I should credit Rosemary Orchard whose script I borrowed from for most of the prompt code.

1 Like