In AskiaScript, a question type variable contains all the information and actions that can be executed on a question, chapter or loop.
The special keyword CurrentQuestion provides useful access to the start question of the routing or the question attached to the inline script context.
To create a question type variable, use askiadesign to create a question, chapter or loop in the survey structure.
In this topic:
See also:
Available only for loops. Returns an array of the specified question at all possible iterations. Takes into account the entire parent loop hierarchy.
Returns an array of Question.
This method iterates as follows:
Top loop first response
Sub loop first response
Sub sub loop first response
sub sub loop second response
...
Sub loop second response
Sub sub loop first response
sub sub loop second response
...
...
Top loop second response
Sub loop first response
Sub sub loop first response
sub sub loop second response
...
Sub loop second response
Sub sub loop first response
sub sub loop second response
...
...
...
' q1 is a question inside only one loop level with 3 iterations q1.AllIterations.Count ' => 3 q1.AllIterations[1].IsLastIteration ' => false q1.AllIterations[1].CurrentIteration.Index ' => 1 q1.AllIterations[2].CurrentIteration.Index ' => 2 q1.AllIterations[3].CurrentIteration.Index ' => 3 q1.AllIterations[3].IsLastIteration ' => true
' q5 is a question inside a loop of loop (loop1 with 2 iterations, loop2 (sub-loop) with 3 iterations)
Dim i
dim str = ""
For i = 1 To q5.AllIterations.Count
str = str + q5.AllIterations.ToString() + "n"
Next
' str will looks like the following (some fragments has been remove for readability):
'{"shortcut":"q5","type":"single","isInLoop":true,"iterations":{"loop1":1,"loop2":1}}
'{"shortcut":"q5","type":"single","isInLoop":true,"iterations":{"loop1":1,"loop2":2}}
'{"shortcut":"q5","type":"single","isInLoop":true,"iterations":{"loop1":1,"loop2":3}}
'{"shortcut":"q5","type":"single","isInLoop":true,"iterations":{"loop1":2,"loop2":1}}
'{"shortcut":"q5","type":"single","isInLoop":true,"iterations":{"loop1":2,"loop2":2}}
'{"shortcut":"q5","type":"single","isInLoop":true,"iterations":{"loop1":2,"loop2":3}}
Only available for questions in a loop. Returns a flattened array, with all values of the question in the loop.
Array of numbers for numeric, single-closed and multi-coded questions in loop (indexes of responses);Array of strings for open-ended questions in loop;Array of dates for date questions in loop;Array of variants for anonymous questions in loop (note: this feature is available from version 5.4.2).
' Q1 is a single question inside a loop with 3 iterations
Q1.AllValues ' => {3; 5; 2}
' Q2 is a multiple question with 3 responses mandatory inside a loop with 3 iterations
Q2.AllValues ' => {3;1;4;2;5;1;4;5;2}
' => Here 3;1;4 are the answers of Q2 for the first iteration of the loop and so on.
' Q3 is an open-ended question inside a loop with 3 iterations
Q3.AllValues ' => {"hello"; "hi"; "goodbye"}
' Q4 is a numeric question inside a loop with 3 iterations
Q4.AllValues ' => {32.5; 47.1; 0}
' Q5 is a single question inside a loop of loop with respectively 3 and 2 iterations
Q5.AllValues ' => {5;3;3;4;1;2}}
' => Here 5;3 are the answers of the first iteration of the outside loop and 5 the answer of the first iteration of the inside loop
' Q6 is a multiple question inside a loop of loop with respectively 3 and 2 iterations
Q6.AllValues ' => {5;3;4;2;1;4;1;2;3;2;4;3;3;2;1;4;1;2}
' => Here 5;3;4;2;1;4 are the answers of the first iteration of the outside loop and 5;3;4 the answer of the first iteration of the inside loop
' Q7 is an open-ended question inside a loop of loop with respectively 3 and 2 iterations
Q7.AllValues ' => {"hello";"world";"hi";"people";"goodbye";"folks"}
' => Here "hello";"world" are the answers of the first iteration of the outside loop and "hello" the answer of the first iteration of the inside loop
' Q8 is a numeric question inside a loop of loop with respectively 3 and 2 iterations
Q8.AllValues ' => {13.5;12;0;5;8.3;9}
' => Here 13.5;12 are the answers of the first iteration of the outside loop and 13.5 the answer of the first iteration of the inside loop
Returns the list of selected responses in the selected order.
Returns a Collection of Responses.
brands.Answers ' => {<Response::3#Pepsi> ; <Response::4#7up>}
Returns the list of available loop items in the selected order and taking into account the MaxVisibleIterations properties of the loop.
If you have 3 iterations on the loop and you set the MaxVisibleIterations to 2 then it will return the 2 first iterations on the first page then the last one on the second page.
This property is mainly used for the ADC in order to limit the number of visible items of the loop on a page. It return dynamically the N number of items per page based on the value given at the MaxVisibleIterations.
If this property is used outside the loop then it reacts as the .Answers property.
Returns a Collection of Loop Responses.
Loop (with Pepsi, 7up and Coca cola and MaxVisibibleIterations set to 2)
Question (Yes, No)
Firt page:
loop.AvailableAnswers ' => {<Response::3#Pepsi> ; <Response::4#7up>}
Second page:
loop.AvailableAnswers ' => {<Response::5#Coca cola>}
Returns the list of available responses in the visible order.
Returns a Collection of Responses.
brands.AvailableResponses ' => {<Response::3#Pepsi> ; <Response::2#Coca-cola>}
Returns the list of direct child questions.
Returns a collection of Questions.
gender.ChildQuestions
Returns the comments of the question.
Returns a String.
Q1.Comments ' => There is a question after
Available only for loops. Returns the response of the loop that references the current iteration.
Returns a Response.
Loop1.CurrentIteration ' => <Response::1#Brand1>
' You can also use it for the comparison If Loop1.CurrentIteration = 1 Then [...] ' If Loop1.CurrentIteration.EntryCodeStr = "UK" Then [...]
Indicates the number of digits allowed for a decimal value.
Returns a Number.
For open-ended questions, this method returns the maximum allowed length. When no decimal is allowed, it returns 0.
age.Decimals ' => 0
temperature.Decimals ' => 1
Indicates a special entry used to specify the "don't know" answer.
Returns a String.
age.DKEntry ' => "999"
Returns the list of errors during the interview associated with the question. This allows ADCs to indicate if there is an error associated with a specific entry, as opposed to the page as a whole.
See also: Error
Returns an Array of Errors.
CurrentQuestion.Errors.Count ' => 0
CurrentQuestion.Errors[1].Key ' => "expected_answer"
CurrentQuestion.Errors[1].Message ' => "A response is expected for question 'q1'"
{% If CurrentQuestion.Errors.Count Then %}
<ul class="question-errors"><li>{%= CurrentQuestion.ShortCaption %}
<ul>
{% Dim errIter
For errIter = 1 To CurrentQuestion.Errors.Count
%}
<li>{%= CurrentQuestion.Errors[errITer].Message %}</li>
{% Next %}
</ul>
</li></ul>
{% EndIf %}
Produces:
<ul class="question-errors"><li>Ranking
<ul>
<li>Rank 2 is missing for question `Ranking`</li>
<li>Rank 3 has been given more than once for question `Ranking`</li>
</ul>
</li></ul>
Indicates whether the question's already an answer (was already asked).
Returns a Boolean.
gender.HasAnswered ' => True
Indicates whether the question's answer is "don't know" (DK).
Returns a Boolean.
gender.HasDK ' => False
Indicates whether the question has a "not asked" answer.
Returns a Boolean.
gender.HasNA ' => False
Indicates whether there is some data in the question (i.e. whether the question was skipped or not).
Returns a Boolean.
gender.HasNoData ' => False
Indicates whether the question has an ancestry chapter. This property searches upwards in the questionnaire hierarchy until it reaches a parent chapter.
Returns a Boolean.
Q1.HasParentChapter ' => True
gender.HasParentChapter '=> False
Indicates whether the question is inside a loop.
Returns a Boolean.
Q1.HasParentLoop ' => True
gender.HasParentLoop '=> False
Indicates whether the question's answer is valid. Applies to open, numeric and closed questions only. This method checks whether a value is present and if so, whether that value is compatible with:
DK settings for all question types;Returns a Boolean.
gender.HasValidData ' => True
Internal unique identifier of the question.
Returns a Number.
gender.id ' => 1
age.id ' => 2
Indicates how the closed question are used for the importation for this question.
0 --> When the question is not a closed question
1 --> Using modality caption
2 --> Using modality order
3 --> Using modality entry code
Returns a Number.
gender.ImportClosed' => 1 (for Using modality caption)
profession.ImportClosed' => 3 (for Using modality entry code)
Indicates that the question is invisible if a data is imported for this question.
Returns a Boolean.
gender.ImportInvisibleWhenImported' => True
profession.ImportInvisibleWhenImported' => False
Indicates the type of importation for this question.
0 --> None
1 --> Entry list (Deprecated)
2 --> ODBC query
3 --> Panel (sent by Cca)
4 --> GeoCATI Field
5 --> Internet parameter
6 --> Platform one
7 --> Fulcrum
8 --> All internet parameter as JSON
Returns a Number.
gender.ImportType ' => 5 (for Internet parameter)
profession.ImportType ' => 3 (for Panel)
Indicates the base code of the HTML input for this question.
Returns a Number.
See also: ADC Generate Askia HTML inputs
' Single gender.InputCode ' => "0"
' Numeric age.InputCode ' => "1"
' Multiple brands.InputCode ' => "2"
' Open comment.InputCode ' => "3"
' Date only birthday.InputCode ' => "4"
' Time only meetingHour.InputCode ' => "5"
Returns the instructions of the question
Returns a String.
Q1.Instructions ' => Please enter some numbers
Indicates whether the question allows a "don't know" answer.
Returns a Boolean.
gender.IsAllowDK ' => false
age.IsAllowDK ' => true
Indicates whether the question is anonymised.
Returns a Boolean.
gender.IsAnonymised ' => false
age.IsAnonymised ' => true
Indicates whether the date question accepts a date only (i.e. without the time).
Returns a Boolean.
MyDateWithoutTime.IsDateOnly ' => true
MyDateWithTime.IsDateOnly ' => false
Available only for loops. Indicates if we are on the first iteration of a loop shown.
Returns a Boolean.
Loop1.IsFirstIteration ' => True
Available only for loops. Indicates if we are on the latest iteration of a loop.
Returns a Boolean.
Loop1.IsLastIteration ' => True
Indicates if the current question is a live routing source.
Returns a Boolean.
Question.IsLiveRoutingSource ' => True
Indicates whether a multi-coded question also records the order of response selections.
Returns a Boolean.
rankingBrands.IsOrdered ' => true
knowingBrands.IsOrdered ' => false
Returns true if the question is skipped.
Returns a Boolean.
gender.IsSkipped ' => true
Indicates whether the date question accepts a time only (i.e. without the date).
Returns a Boolean.
MyTimeWithoutDate.IsTimeOnly ' => true
MyTimeWithDate.IsTimeOnly ' => false
Indicates if for the open ended question, Uppercase is ticked.
Returns a Boolean.
MyOpen.IsUppercase ' => true
MyOpen.IsUppercase ' => false
Return the Question object of the source link question.
Returns a Question.
MyQuestion.LinkSourceQuestion.Shortcut ' => MySourceQuestion
Indicates if Link to top level responses and make headers selectable is ticked.
Returns a Boolean.
MyQuestion.LinkTopLevel ' => true
MyQuestion.LinkTopLevel ' => false
Indicates the type of link used on the question.
0 --> None
1 --> All responses
2 --> All selected responses
3 --> All non selected responses
4 --> Selected responses in all linked questions
Returns a Number.
MyBrands.LinkType ' => 3 (for All non selected responses
Returns the long caption of the question, in the current language.
Returns a String.
gender.LongCaption ' => "Are you..."
Indicates the maximum allowed value for a date question.
When no maximum has been specified, this method returns DK.
Returns a Date.
' Date question with maximum date "31/12/2013" MyDate.MaxDate ' => #31/12/2013#
' Date question without maximum value MyDate.MaxDate ' => DK
Indicates the question's maximum expected value, number of responses or length, depending on the question type:
When no maximum is expected, this method returns DK.
Returns a Number.
' Multi-coded question with maximum 5 responses Brands.MaxValue ' => 5
' Numeric question with 99 as maximum value age.MaxValue ' => 99
' Open-ended question with 5 maximum characters postalCode.MaxValue ' => 5
' Question without maximum value CurrentQuestion.MaxValue ' => DK
Returns the MaxVisibleIterations properties set on a loop.
If you have 3 iterations on the loop and you set the MaxVisibleIterations to 2 then it will return the 2 first iterations on the first page then the last one on the second page.
Returns a Number (0 if All iterations set on the loop).
MaxVisibleIterations set to 2 loop.MaxVisibleIterations ' => 2 MaxVisibleIterations set to All iterations loop.MaxVisibleIterations ' => 0
Indicates the minimum allowed value for a date question.
When no minimum has been specified, this method returns DK.
Returns a Date.
' Date question with minimum date "01/01/2013" MyDate.MinDate ' => #01/01/2013#
' Date question without minimum value MyDate.MinDate ' => DK
Indicates the question's minimum possible value, number of responses or response length, depending on the question type:
When no minimum is expected, this method returns DK.
Returns a Number.
' Multi-coded question with minimum 3 responses Brands.MinValue ' => 3
' Numeric question with 18 as minimum value age.MinValue ' => 18
' Open-ended question with 5 minimum characters ' This example is currently fictional because the ' system doesn't have a minimum length value ' for open-ended question postalCode.MinValue ' => 5
' Question without minimum value CurrentQuestion.MinValue ' => DK
Only available for questions that have an ancestry chapter. Returns the first ancestry parent chapter.
Returns a Question.
Q1.ParentChapter ' => <Question::Chapter>
Only available for a question inside a loop. Returns the parent loop question.
Returns a Question.
Q1.ParentLoop ' => <Question::Loop>
Returns the parent question.
Returns a Question.
gender.ParentQuestion
Returns the list of all the child questions.
Returns a collection of Questions.
gender.Questions
Returns the entire list of responses for a closed question.
Returns a Collection of Responses.
gender.Responses ' => {<Response::1#Man> ; <Response::2#Woman>}
Returns the content of the seed rotation applied to the question.
-2 --> Reused for question with same number of responses
-1 --> Different for every question
Any other positive number --> Defined by seed
Returns a number.
gender.RotationSeed ' => -1 (for Different for every question)
Returns the type of rotation applied to the question.
0 --> Never
1 --> Randomise
2 --> Rotate
3 --> Invert
4 --> Alphabetical
Returns a number.
gender.RotationType ' => 3 (for inverted)
Returns the list of scenarios applied for a question.
Returns an array of string.
gender.Scenarios ' => {"Client";"NonClient"}
Returns the short caption of the question, in the current language. If the ShortCaption is empty, then it returns the LongCaption.
Returns a String.
gender.ShortCaption ' => "Respondent Gender"
Returns the question shortcut (the name of the variable).
Returns a String.
gender.Shortcut ' => "gender"
^1. appreciation^.Shortcut ' => "1. appreciation"
Returns an Array of String.
gender.Tags ' => {"tag1";"tag2"}
gender.Tags.Count ' => "2"
gender.Tags[2] ' => "tag2"
Returns the question type as a string. The possible types are:
Returns a String.
gender.Type ' => "single"
brands.Type ' => "multiple"
age.Type ' => "numeric"
comment.Type ' => "open"
birth.Type ' => "datetime"
gridLoop.Type ' => "loop"
iterationSelectionLoop.Type ' => "single-loop"
preliminarySelectionLoop.Type ' => "multiple-loop"
numericSelectionLoop.Type ' => "numeric-loop"
Returns the data stored in the User Data field.
Returns a String.
gender.UserData ' => "some text"
CurrentQuestion.UserData ' => "some JSON"
Returns the value(s) (answers) of the question in the current iteration.
When there is no response, the value returned is DK, except in the case of open-ended and multi-coded questions:
Number for numeric and single closed questions (indexes of the responses);String for open-ended questions;Array of numbers for multi-coded questions;Date for date questions;Variant for anonymous questions (note: this feature is available from version 5.4.2).gender.value ' => 1
age.value ' => 33
brands.value ' => {3; 5; 6}
q1_other.value ' => "bla bla bla"
birthday.value ' => #14/02/1978#
When no value is specified:
gender.value ' => DK
age.value ' => DK
brands.value ' => {}
q1_other.value ' => ""
birthday.value ' => DK
Indicates the status of the visibility of the variable.
0 --> None
1 --> Only sub questions
2 --> Full
Returns a Number.
gender.Visibility ' => 2 (for Full)
Indicates if the variable is visible during data entry.
Returns a Boolean.
gender.VisibleInDataEntry ' => True
age.VisibleInDataEntry ' => False
Equivalent to the routing action change order. Changes the order of any direct sub-questions and returns the question for the call chain. This method is available only when running R/W scripts not when evaluation conditions.
Returns a Question.
Dim randomOrder = {1; 2; 3}.Shuffle()
ChapterQuestionnaire.ChangeSubQuestionsOrder(randomOrder)
Returns the index(es) (base 1) of the specify entry code(s).
country.EntryCodeToIndex("US") ' => 1
country.EntryCodeToIndex({"US"; "DUMMY"; "UK"}) ' => {1; DK; 2}
return the URL to use to go to this question.
Returns a String.
Note: In order to use it for a nagivation, the URL used in a href should include at the end of the GoToUrl() link the shortcut of the question like this:
age.GotoURL()
Same as IndexToEntryCodeStr, but converts the return value(s) to number(s).
brands.IndexToEntryCode(1) ' => "001" brands.IndexToEntryCode(1) ' => 1
Returns the entry code(s) of the response(s) at the specified index(es).
country.IndexToEntryCodeStr(1) ' => "US"
country.IndexToEntryCodeStr({1; -3; 2}) ' => {"US"; ""; "UK"}
Indicates the base name of the HTML input for this question.
type is "List".Returns a String.
Parameter
See also: ADC Generate Askia HTML inputs.
' Single gender.InputName() ' => "U0"
' Numeric age.InputName() ' => "C1"
' Multiple brands.InputName() ' => "M2"
' Open comment.InputName() ' => "S3"
' Date only birthday.InputName() ' => "D4"
' Time only meetingHour.InputName() ' => "T5"
' Date and time
departure.InputName("date") ' => "D5"
departure.InputName("time") ' => "T5"
' Ranking question
brands.InputName("ranking") ' => "R2"
' List with multiselection
brands.InputName("list") ' => "L2"
Returns the HTML-escaped version of the Question.Value, to prevent interpretation of the < and > characters and also for special unicode characters.
Returns a String.
Also see: ADC Generate Askia HTML inputs
gender.InputValue() ' => "256"
brands.InputValue() ' => "256,257"
comment.InputValue() ' => "If < 200 and not > & that "work"" ' Where comment.Value return: ' "if < 200 and not > & that "works""
age.InputValue() ' => "33"
birthday.InputValue() ' => "12/12/2012"
departure.InputValue("date") '=> "24/05/2012"
departure.InputValue("time") '=> "12:05:00"
Returns a question inside a loop, at a specific loop index.
Returns a Question object
The number of parameters for this method is dynamic and is equal to the number of the parent loops:
We recommend that you specifically indicate the loop name using the following syntax:
Question.Iteration(LoopName1 : LoopIndex1, LoopName2 : LoopIndex2)
In this case, the order of the parameters doesn't matter, and the previous syntax is equivalent to this
Question.Iteration(LoopName2 : LoopIndex2, LoopName1 : LoopIndex1)
Alternatively, this syntax also works :
Question.Iteration(LoopIndex1, LoopIndex2)
The first parameter refers to the immediate parent loop, the second parameter refer to the next loop above and so on. While less verbose, this syntax is more prone to scripting errors.
' Q1 is inside a loop named "loop" Q1.Iteration(1) '=> Q1 in the first iteration
' Q1 is inside a loop named "loop" Q1.Iteration(loop : 2) ' => Q1 in the second iteration
' Q1 is inside a loop named "loop" Q1 '=> Q1 in the current iteration
' Q1 is inside two nested loop "subLoop" which is inside "topLoop"
Q1.Iteration(1) ' => Q1 in the first iteration of the 'subLoop' loop
' and in the current iteration of the 'topLoop' loop
' Q1 is inside two nested loop "subLoop" which is inside "topLoop"
Q1.Iteration(1, 2) ' => Q1 in the first iteration of the 'subLoop' loop
' and in the second iteration of the 'topLoop' loop
' Q1 is inside two nested loop "subLoop" which is inside "topLoop"
Q1.Iteration(topLoop : 2) ' => Q1 in the second iteration of the 'topLoop' loop
' and in the current iteration of the 'subLoop' loop
' Q1 is inside two nested loop "subLoop" which is inside "topLoop"
Q1.Iteration(topLoop : 2, subLoop : 1) ' => Q1 in the second iteration of the 'topLoop' loop
' and in the first iteration of the 'subLoop' loop
Example : checking of the value of Q1 is > 0 during the 3rd iteration of LoopName
Case 1 : the filter is inside the current loop
When the filter is on the current loop flow, parameters are optional.
Q1.Iteration(LoopName1 : LoopName.CurrentIteration)
becomes equivalent to
Q1
So, we can use
Q1.value > 0 AND LoopName.CurrentIteration = 3
Case 2 : the filter is outside the current loop
When the script is used outside the loop flow, all parameters are required.
Q1.Iteration(LoopName : 3) > 0
Ask only the questions shortcuts present in the Questions parameters and in the same order they appear in the parameter. This is available only when running R/W scripts, not when evaluating conditions.
Questions (string): The list of questions shortcut to ask separated by semi-colon ";"
Chapter Q1 Q2 Q3 Q4 Chapter.OnlyAskSubQuestions(“Q3;Q1”) which would hide Q2 and Q4 and show Q3 and Q1 first
Equivalent to the routing action set value.
Sets the specified value(s) in the specified question and returns the question for the call chain. This is available only when running R/W scripts, not when evaluating conditions.
Returns a Question.
If age < 18 Then ageRecod.SetValue(1) Else If age >= 18 And age < 26 Then ageRecod.SetValue(2) Else If age >= 26 And age < 36 Then ageRecod.SetValue(3) Else If age >= 36 And age < 50 Then ageRecod.SetValue(4) Else ageRecod.SetValue(5) EndIf
' Example with call chain
If brands has {1; 2} Then
q2.SetValue({1; 2}).SkipAndKeepData()
EndIf
Equivalent to the routing action do not ask.
Skips the question and does not keep its data. This is available only when running R/W scripts, not when evaluating conditions.
Returns a Question.
If age < 18 Then AdultQuestions.Skip() EndIf
Equivalent to the routing action make question invisible.
Skips the question and keeps its data, returning the question for the call chain. This method is available only when running R/W scripts, not when evaluation conditions.
Returns a Question.
If age < 18 Then AdultQuestions.SkipAndKeepData() EndIf
' Example with call chain
If brands has {1; 2} Then
q2.SkipAndKeepData().SetValue({1; 2})
EndIf
Returns a string which represents the question object (expressed in JSON format).
Returns a String.
' Output in a single line (it's break here for the readability)
gender.ToString()
' => {
"shortcut":"gender",
"shortCaption":"Respondent gender",
"longCaption":"Are you?",
"type":"single"
}
' Output in a single line (it's break here for the readability)
' q1 is in loop of loop
q1.ToString()
' => {
"shortcut":"q1",
"shortCaption":"Q1",
"longCaption":"Q1",
"type":"single",
"iterations":{"parentLoop":4,"subLoop":2}
}
Always returns "question".
Returns a String.
gender.TypeOf() ' => "question"
Operators for a question are equivalent to operators for a question value. For example:
Q1 has {1;2;3}
' Equivalent to
Q1.value has {1;2;3}
' Equivalent to
??Q1?? has {1;2;3}
The question value (or values) will be a number, string, date or array, according to the question type.