Prompt to ask for a number that I can then use in a script

Hi,

I have this line of Javscript:

draft.content = draft.processTemplate("[[line|..7]]")

I want to replace the „7“ with a number that the Action asks before running (using 7 as default answer).

Can anybody help me with that, would be awesome, thanks a lot.

You want the input to be something you type each time, or is it always going to be an a range where it’s easier to hit a button (e.g. is it always going to be 3,4,5,6, or 7)?

No, type it in each time

This is the script to create and show a simple prompt with one text input (modified from example in docs):

let p = new Prompt();
p.title = "Number of Lines";
p.message = "Enter number of lines";
p.addTextField("noLines", "Lines", "7");
p.addButton("Continue");

if (p.show()) {
    // retrieve value from prompt
    let noLines = p.fieldValues["noLines"]; // this is now "7", or whatever you entered
    // now build a template with that value
    let template = `[[line|..${noLines}]]`;
    // apply the template, per your above 
    draft.content = draft.processTemplate(template);
}
1 Like

I would even write this to get the number keyboard and ease the typing:

p.addTextField(“noLines”, “Lines”, “7”, {“keyboard”:“numberPad”});

2 Likes