Category: Script Library
prompterHelper
Helper library to provide different Prompter abstractions to make it easier to use the popup prompter.
Three different type of helpers are provided:
picklistPrompter
A simple prompter to select a value from a list or from a named picklist.
The defaultSelection is optional.
picklistPrompter(title, text, list, defaultSelection="")
List example:
// Load prompterHelper
document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
// Check picklistPrompter
try {
await picklistPrompter("Title", "Selection", ['alpha', 'beta', 'gamma', 'delta'], 'delta')
console.log(prompterVar + " selected");
} catch (errorText) {
console.log('cancelled picklistPrompter: ' +errorText);
}
Picklist example:
// Load prompterHelper
document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
// Check picklistPrompter
try {
await picklistPrompter("Title", "Selection", "colorOptions", "red")
console.log(prompterVar + " selected");
} catch (errorText) {
console.log('cancelled picklistPrompter: ' +errorText);
}
yesnoPrompter
A simple prompter requesting a yes/no answer.
The yes and no arguments are optional and can be used like "continue" and "cancel".
yesnoPrompter(title, yes="yes", no="no")
Example use:
// Load prompterHelper
document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
// Check yes-no prompter
console.log('* Test: yesnoPrompter');
try {
await yesnoPrompter('Confirmation question? (sel yes)');
console.log('Okay, yes clicked');
await yesnoPrompter('Confirmation question? (sel oui)', yes="Continue", no="Cancel");
console.log('Okay, Continue clicked');
} catch (errorText) {
// user clicked 'No'
console.log('cancelled yesnoPrompter: ' + errorText);
return;
}
textPrompter
A simple prompter requesting a text input.
text and defaultText are optional.
textPrompter(title, text="", defaultText="")
Example use:
// Load prompterHelper
document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
// Check textPrompter
try {
await textPrompter("Title", "Enter text", "The sky is blue!")
console.log(prompterVar + " entered");
} catch (errorText) {
console.log('cancelled textPrompter: ' +errorText);
}
Usage
The Propmper API is non-blocking meaning the code following the Prompter is executed without waiting for user input. I use the javascript Promise feature to make the Prompter blocking. Following example shows how to use it:
# To use, call the script from main script with:
document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
# Example implementation:
async function myFunction() {
try {
await xxxPrompter('Confirmation question?');
} catch (errorText) {
// user clicked 'No'
console.log('cancelled with '+errorText, "#ff0000");
return errorText;
}
// user clicked 'yes', continue with function main code here
console.log('continue from yes');
}
myFunction();
Installation
The prompterHelper script is installed using the scriptHandler script about which you can learn more over here. It is installed in the Scripts form.
Dependencies
none
ChangeLog
Link to ChangeLog
Author
- Daniel Leu, info@danielleu.com
Do you like this script? Are you using it? Please consider supporting me by buying me a coffee!
Thanks!
Last modified: Apr 24, 2025 6:28:09 PM
