Get the selected value from a list prompt

I’m sort of new to scripting here, and have found some useful starting points. However, I’ve run into a block (although I’m sure it’s blindingly obvious with a little bit of knowledge)…

I have a list of projects stored in an archived draft. I am reading this list in to create a select list prompt using the “Script” action. My script is:

// get the real UUID value from (i) info for your draft with the list
let d = Draft.find("FCEAA5F4-0B02-48F5-AB57-136505A8BDA5");
// 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 = "Project";
 p.message = "Select a project"
 p.addSelect("project", "Project", selections, [], false)
 p.addButton("OK");
 var selection = p.show()
draft.setTemplateTag("project",selection)
 draft.update()

My problem is that I cannot seem to get the value that the user selects from the list. At present my draft.setTemplateTag("project",selection) returns TRUE (since something was selected). But, for the life of me, I cannot seem to access the value of what was selected.

Can anyone point me to where I can get the value so I can create the templateTag?

Many thanks

See if this helps…

// get the real UUID value from (i) info for your draft with the list
const projectsDraftUUID = "FCEAA5F4-0B02-48F5-AB57-136505A8BDA5";
let d = Draft.find(projectsDraftUUID);

let selections = [];
// loop over the lines to add to your prompt...
for (let item of d.lines) 
{
    selections.push(item);
}

let p = Prompt.create();
p.title = "Project";
p.message = "Select a project";
p.addSelect("project", "Project", selections, [], false);
p.addButton("OK");

//Check the results if not cancelled
if (p.show())
{
    let selectedProject = p.fieldValues["project"];
    alert(selectedProject);
}
2 Likes