Introduction
This article describes how to create prompts in a QScript for the user to enter values, confirm options, and make selections.
Requirements
- The importdata.zip file which includes the Phone data set that we will use for this article.
- You have read How to Create a Custom QScript and How to Work with Variables via QScript.
- You are using the QScript Editor method from How to Use QScripts in Q.
Method
By default, basic prompts can be used without referencing any additional QScript libraries. Here are some examples.
General
1. Text or value
prompt("Enter a value");
2. Boolean (true/false)
askYesNo("Do you wish to continue?")
3. Confirmation
confirm("The script will now run")
Selection Functions
Q has its own JavaScript library of selection functions called QScript Selection Functions. The following are some of the main functions from this library and all require the below line at the top of your code:
includeWeb('QScript Selection Functions')
In each example, you must first declare the variable or question to use in the prompt.
1. Select single question by question name
var questions = project.dataFiles[0].questions;
var selection = selectOneQuestion("Please select a question",questions);
questions
stores all questions in the data set.selectOneQuestion
returns aquestion
object.
2. Select multiple questions by question name
var questions = project.dataFiles[0].questions;
var selection = selectManyQuestions("Please select multiple questions",questions).questions;
questions
stores all questions in the data set.selectManyQuestions
returns aquestion
object when.questions
is appended.
3. Select single variable by label
var variables = project.dataFiles[0].variables;
var selection = selectOneVariableByLabel("Please select one variable",variables);
variables
stores all variables in the data set.selectOneVariableByLabel
returns avariable
object by default but will return the selected label if.label
is appended.
4. Select multiple variables by label
var variables = project.dataFiles[0].variables;
var selection = selectManyVariablesByLabel("Please select multiple variables",variables);
variables
stores all variables in the data set.selectOneVariableByLabel
returns avariable
object by default but will return the selected labels if.labels
is appended.
Next
How to Create Diagnostic Messages and Perform Validations via QScript
Later
How to Modify Variables and Value Attributes via QScript
How to Create Custom Variables via QScript
How to Add Folders and Text Outputs via QScript
How to Create Tables and R Calculations via QScript
How to Create a Chart via QScript
How to Modify Tables via QScript
See Also
How to Work with Variables via QScript
How to Create a Custom QScript
Comments
0 comments
Article is closed for comments.