Submit a ticket My Tickets
Welcome
Login

Survey builder - Functions

  

Please see the tables below for an introduction and short-cuts into the functions of Survey Builder.




Scripts are used to provide special functions that are not part of the built-in logical language of Survey Builder. Scripts can be used in filters, answer control and reference to questions.

In Survey Builder scripts are implemented in C#. Function names follow a standard naming syntax, and in general functions do not have fixed numbers of parameters. E.g. script:Sum(1,2,3,4,5,6,7,8,9) will sum 9 numbers.


NB: Use your mouse or the arrow keys to scroll left/right - it may be easier to copy and paste these tables into Excel.

 

ScriptDescriptionParametersExamples
AdjustTime, TimeAdjModify the current time by the number of hours provided.script:AdjustTime(parameter1)script:AdjustTime(2)
 Positive and negative numbers can be provided. script:TimeAdj(parameter1)script:TimeAdj(2)


 This will add two more hours on top of the current time (GMT)
AdjustTimeNowH, Adj_TimeNowHReturns the current time in the same format adjusted by the number of hours specified.script:AdjustTimeNowH(parameter1)script:AdjustTimeNowH(2)
 script:Adj_TimeNowH (parameter1)script:Adj_TimeNowH(2)

 Retuns the time in required format
AdjustTimeStartF, Adj_TimeStartFReturns the questionnaire start time adjusted by the number of hours specified.script:AdjustTimeStartF(parameter1)script:AdjustTimeStartF(020202)
 On a format of hhmmss. Can be used in data type: Numeric script:Adj_TimeStartF (parameter1)script:Adj_TimeStartF(020202)


 Retuns the new time in required format with adding the 2 hours, 2 minutes and 2 seconds to the current time
AutoCodeIt is possible to add pre-filled text from an Excel-file to a survey.
https://static.quenchtec.net/46033bcf-0124-4b26-b4ea-30726bd5357c/54SRV1uNcvN/Check-ZIP-CITY.xlsx
For example, we have a question in the survey asking for a ZIP code. Then we the Excel file where the ZIP code will be verified, and then it provide us the CITY automatically.
You need to create an Excel file, with all the ZIP codes, and then a column for CITY.
There must be a sheet called Sheet1, in the header above all columns following normal "variable" conventions, e.g. just use a-z, 0-9, like "amount", "age" etc (no spaces).
 All columns should be formatted as text fields, even though they contain numbers. You need some column to use as the lookup column, e.g. a company "number".
CodeLess1Creates a range, typically to be used single-choice question from 1 to one less than the codescript:CodeLess1(code)script:CodeLess1(10)
 Result: 1:9
CodeUpToNCreates a range, typically to be used on numeric questions.script:CodeUpToN(code)script:CodeUpToN(10)
 Result: 0:10
CodeXorTypically used to select the "XOR" function between two multiple-choice questions. The result is all codes that have only been selected in one of the two, but not both.script:CodeXor(Question1,Question2)script:CodeXor(\BrandsKnown.a,\BrandsUsed.a)
 If BrandsUsed is filtered on BrandsKnown, it will return BrandsKnow but not used.
ConcatConcatenes any number of valuesscript:Concat(v1,v2,v3...)script:Concat(\@sys_date,' Calender')
 Result: 20200101 Calendar - if \@sys_date=20200101
CreateShortURLKeyReturns the 8 number/characters that should go after https:\\url.quenchtec.netscript:CreateShortURLKey([any_link]) script:CreateShortURLKey([any_link])
This will return the 8 number/characters that should go after https:\\url.quenchtec.net
That way in redirects, email invites send form a survey etc,
 You can use a short link rather than the long https://quenctec.net/p?qis=....&qif=.... etc
CurrentAgeCalculates the age based on yearBorn and this yearscript:CurrentAge(yearBorn,thisYear)script:CurrentAge('1990',\@sys_year)
 Result:If the current year is 2020, then returns 30.
DiffCalculates the difference between value1 and value2, noAnswerValue is substituted if the referenced question has no answerscript:Diff(value1,value2,noAnswerValue)script:Diff(\Number1.a.1,\Number2.a.1,0)
Diff0Computes the difference between number1 and number2. If any referend question has no answer, uít will be substituted by noValueNumber.script:Diff0(number1,number2,noValueNumber)script:Diff0(\number1.a.1,\number2.a.1,0)
 If the difference is negative, 0 is returned
DiffNegComputes the difference between number1 and number2. If any referend question has no answer, uít will be substituted by noValueNumber.script:DiffNeg(number1,number2,noValueNumber)script:DiffNeg(\number1.a.1,\number2.a.1,0)
 If the difference is negative, the "absolute" value is returned,
DivReturns the division of any number of valuesscript:Viv(value1,value2,value3...)script:Min(100,10,2)
 Result:5
EchoUsed to just return the values, typically for debuggingscript:Echo(value1,value2,value3...)script:Echo(\BrandsKnown.a,'hello')
 Result:Any values selected from \BrandsKnown followed by "hello"
EmailNReturns 2 to 4 email addresses concatenated with a ","script:EmailN(e1,e2,...eN.)script:Email2('email1@xxx.com','email2@zzz.com')
 Replace N in the script with 2,3 or 4. Result:email1@xxx.com,email2@zzz.com
FormatStringBuild a string based on a template, with substitutions of any values.script:FormatString(template,v0,v1,v2,v3.....)script:FormatString('https://survey.quenchtec.net/p?qif={0}&qsid={1}&amp,\@sys_baselineid,\@sys_qsid)
template - specify a string (enclosed in single quotes) with placeholders for where the values should be substituted. Result: https://survey.quenchtec.net/p?qif=83dfb689-4859-4999-b291-29b15a203bdb&qsid=47033bcf-0124-4b26-b4ea-30726bd5357c
 v0, v1, v2 .... values to be substituted, can be strings or addresses to questions etc
FromToSet a range between the "from" value and the "to" value.script:fromto(from,to)script:fromto(0,\Q2.a.1)
 It will return an "interval" that can be used in answer control, like "0:100" restricting the user to enter a value between 0 and 100. Typically one or both parameters are references to other numeric questions where they previously have entered a value. Will return a interval from "0" to the answer from "Q2.a.1" (this needs to be a numeric question). If the answer to "Q2.a.1" is 230, it will return "0:230"
HashSumCreates a range, typically to be used on numeric questions that represents a sumscript:HashSum(sumValue)script:HashSum(100)
 Result:#100
HttpReqHttpReq - Send a HttpRequest using "GET" methodscript:HttpReq(url,p1,v1,p2,v2,....)script:HttpReq('https://myserver.com','user','xyz','date',\@sys_date)
 Does a "get" request on an URL with optional parameters. The result from the "GET" is returned p1,v1,p2,v2... these are optional name=value pairs that will be appended to the URL. Will do a "GET" request on: https://myserver.com?user=xyz&date=20220101
IsEqualCompare if two values have the same value. To be used when you want to check if question Q1 has the same value as question Q2. The function returns a value of 1 if equal or 0 if not equal.script:isequal(parameter1,parameter2)script:isequal(\Q1.a.1,\Q2.a.1)
It can be used to automatically fill in a numeric question (that will get response 0 or 1). This will return the value 1 when the two questions have the same value. 
 Or to fill in a single choice questions with two rows (row1 with code value of 0 and row2 with code value of 1)
JoinJoin any number of values with the separator joining each valuescript:Join(separator,v1,v2,v3....)script:Join('-','value1','value2')
 Result:value1-value2
LengthOfReturns the length of the value/stringscript:LenghtOf(value)
LIndexReturns the 1 based index of the "needle" forung in the "hashSeperatedList"script:LIndex(needle,hashSeperatedList)script:LIndex(\@sys_lang,'en#de#no#sv')
 Result:2 if \@sys_lang=de
MaxReturns the maximum value of any number of valuesscript:Max(value1,value2,value3...)script:Max(4,7,8,1)
 Result:8
MaxIndexReturns a 1 based index of the maximum value of the parameters.script:MaxIndex(v1,v2,v3....)script:MaxIndex(\grid.a.1,\grid.a.2,\grid.a.3,\grid.a.4)
 Result:2 - if the second parameter has the highest value.
MinReturns the minimum value of any number of valuesscript:Min(value1,value2,value3...)script:Min(4,7,8,1)
 Result:1
MinIndexReturns a 1 based index of the minimum value of the parameters.script:MinIndex(v1,v2,v3....)script:MinIndex(\grid.a.1,\grid.a.2,\grid.a.3,\grid.a.4)
 Result:2 - if the second parameter has the lowest value.
MultReturns the multiplication of any number of valuesscript:Mult(value1,value2,value3...)script:Mult(1,2,3)
 Result:6
Multi Answer CountCalculates the amount of answers in a particular questionscript:multiAnswerCount(Questionlabel)script:multiAnswerCount(Q1)
QuarterReturns the quarter, based on the datescript:Quarter(date)script:Quarter(\@sys_date)
 Result:3 if sys_date=202000701
RandomMultiTypically used to create a series of random numbersscript:RandomMulti(start,end,NumberToPick,randomSeed)script:RandomMulti(1,10,3,\@sys_ramdom)
start - First value to pick Result: 7;3;2 - As an example, the returned values are not sorted
end - Last value to pick from
NumberToPick - How many random numbers do we want to pick
 randomSeed - Seed to be used
RandomSingleFromListPick a single random number from a list for random generated numbers. To be used when you want a series of "unrelated" random numbers, where you then can pick one by one of these to be used in various questionnaire logic. The function first creates a list of random numbers and then return the one you selected from the list.script:RandomSingleFromList(RangeStart,RangeEnd,RangeCount,Seed,Item)script:RandomSingleFromList(1,1000,10,\@sys_random,5)
RangeStart - Specify the lowest possible random number you want created in the list This will generate a list of 10 random numbers between 1 and 1000, using sys_random as seed, and return the 5th item in the list. If the list is "311,451,486,506,539,639,738,871,903,963" the 5th item is "539".
RangeEnd - Specify the largest possible random number you want created in the list
RangeCount - Specify the number of random numbers you want created in the list (this number should be less than the interval defined by the RangeStart-RangeEnd
Seed - Specify a seed to be used for the random generater. Typically you will use the "sys_random" variable that is a random number between 0 and 1000 created at the start of an interview. This will ensure that the list of random numbers will the same for one given respondent.
Item
 Specify the item you want returned from the list
RedirectThe most common URL type is what we call "Parameter based". This structure has a "base URL", followed by a "?" (question mark), followed by one or more pairs of parameters that have a "name" and "value" separated by "=" (equal sign). Each pair, in turn, is separated by a "&" (ampersand sign).script:redirect(baseurl,p1,v1,p2,v2,p3,v3........)script:redirect('https://yourlink.com','survey','XYZ123')
The other not-so-common type is what we called "Path-based". This structure just have a series of values, separated by "/" (slashes). This type should not have any special symbols like "?", "&", or "=" as part of the URL.Where p1 = parameter1 and v1 = value1, etc.
 Finally, there also exists some "Hybrid based" structures, that do not adhere to the common ones. These are quite rare. Using this script it is very important to remember that there should be NONE of the special symbols used to create the URL, like the "?", "&" and "=". These are ALL inserted at appropriate places by the script.
lf(QID, flt, numToPick, randomseed)This function is used to run real-time analysis on a dataset (questionnaire) to determine the counts for the options (categories) in the question. Based on the counts, and the codes qualifying, one or more categories are picked based on a least-fill (the categories with the lowest counts are picked first). In principle, the analysis dataset can be a different one than the one we are programming, and the analysis question can be a different one from the one we are in, so there is no automatic connection between the question/questionnaire we are in and the script function. Hence, all parameters must be carefully considered. Also the difference between static parameters that are in single quotes, and dynamic/references that are not in single quotes and are typically introduced by "\" (backslash character).lf(QID, flt, numToPick, randomseed)script:lf(LF.a,\L1.a,2,\@sys_random)
QID: Question ID to be punched
flt: This is a reference to the question that contains the qualifying codes (options). This must always be a reference, aka it should NOT be in single quotes, and always start with a ""\"". Usually, this is a sub-question within the question we are programming, and hence we can use the shorthand notation like ""\.a"" meaning the subquestion a (first subquestion, within the question we are programming.
numToPick: This is the maximum number of categories that we should pick of the ones qualifying.
randomSeed: This is a seed used by the random generator to pick randomly, if more several options have the same counts, or if the analysis fails.
 Returns the lowest value from a question to determine which answer/cell needs to get selected"
SelectFirstNTypically used to select a codes from a multi-choice questionscript:SelectFirstN(ListToPickFrom,IndexToPick)script:SelectFirstN(\BrandsKnown.a,1)
ListToPickFrom - Typically reference to a multiple-choice question Result: 3 - if 3 is the first code selected in question \BrandsKnown
 IndexToPick - One based index of code to pick
SelectNPick the "Nth" value from a multiplechoice questionscript:SelectN(MultipleChoiceQuestion,valueToPick)script:SelectN(\Brands_Known.a,2)
 Result: Returns the second code the respondent gave to question BrandsKnown
SelectOneFromListReturns one value from a list of values. The index is one based. Typically used in combination with "MinIndex" and "MaxIndex".script:SelectOneFromList(index,v1,v2,v3....)script:SelectOneFromList(1,\q1.a,\q2.a)
 Result: Returns the value from Q1
SelectRandomNTypically used to select a number of codes from a multi-choice questionscript:SelectRandomN(ListToPickFrom,NumberToPick,randomSeed)script:SelectRandomN(\BrandsKnown.a,3,\@sys_random)
ListToPickFrom - Typically reference to a multiple-choice question Result:1;3;5 - if 1, 3 and 5 afre between the codes selected at \BrandsKnown
NumberToPick - How many codes should we pick
 randomSeed - Seed to be used if more codes than we request are
SelectTopXFromRowsTypically used in a grid question, to select a number of rows that should be used later, based on the code value of the row.script:SelectTopXFromRows(v1,v2,v3,v4,v5.....numberOfRowsToPick,maxValueToPick,randomSeed)script:SelectTopXFromRows(\grid.a.1,\grid.a.2,\grid.a.3,\grid.a.4,2,5,\@sys_random)
v1,v2,v3... - Tyically reference to the row 1,2,3 etc of a grid question
numberOfRowsToPick - How many rows should we pick (e.g. top 5)
maxValueToPick - The highest code-value that we want to include in the pick (e.g. to avoid picking "99 - None of these"
 randomSeed - Seed to be used to pick if we have multiple rows with the same value that qualifies
SingleAutoCodeLooks for "needle" in the hash (#) delimited string "hasSepListIn", if found, returns the corresponding value form "hasSepListout", if not found, returns "notFoundValue".script:SingleAutoCode(needle,hashSepListIn,hashSepListOut,notFoundvalue)script:SingleAutoCode(\@sys_lang,'en#dk#se#no','1#2#3#4','99')
 Result: 2 if \@sys_lang=dk, if not found, 99
SubstrReturns a 1 based substring of stringscript:Substr(string,start,length)script:Substr(\open.a,1,2)
 Result:Returns the first two characters of question \open.a
SumCalculates the sum of 2 to 15 numbers. If any number is non-numeric it is set to 0script:sumN(N=2-15)script:sum8(\Q1,\Q2,\Q3,\Q4,\Q5,\Q6,\Q7,\Q8)
 This will automatically create the sum of 8 questions
TimeDiffHComputes the time difference in minutes between two questions of type "duration"script:TimeDiffH(starttime,endtime)script:TimeDiffH(\StartTime.a.1,\EndTime.a.1)
 Result:15  - if the difference is 15 minutes
TimeDiffSecondsCalculate the time difference between two paramters in secondsscript:timediffseconds(starttime,endtime)script:timediffseconds(\StartTime.a.1,\EndTime.a.1)
ToMaxCreates a range, typically to be used on numeric questions. "1" is automatically added to the "start" valuescript:ToMax(start,end)script:ToMax(1,10)
 Result:2:10
ToMinCreates a range, typically to be used on numeric questions. "1" is automatically subtracted from the "toValue".script:ToMin(toValue,startValue)script:ToMin(10,1)
 Result:1:9
UrlEncodeUrl encode any text string to make sure it can be passed as a parameter in a URL requestscript:UrlEncode(value)script:UrlEncode('myep1=somev1&nationalname=Bjørn')
 Result:myep1%3Dsomev1%26nationalname%3DBj%C3%B8rn










Answer control
Functions
Question filterAutomatically fill in answerfilter a-zrow filterRedirect on exitMaskingValidation
AdjustTimexx




AdjustTimeNowHxx




AdjustTimeStartFxx




AutoCodexxxxx

CodeLess1




xx
CodeUpToN




xx
CodeXor
x


xx
Concat
x

xxx
CurrentAgexxxx


Diffxxxx
xx
Diff0xxxx
xx
DiffNegxxxx
xx
Divxxxx
xx
Echo
x

xx
FormatString
x

x

FromTo




xx
HashSum





x
HttpReqxxxxxxx
IsEqualxxxx


Join
x

xx
LengthOfxxxx
x
LIndex
x


x
Maxxxxx

x
MaxIndex
x


x
Minxxxx

x
MinIndex
x


x
Multxxxx
x
MultiAnswerCountxxxx
x
Quarterxxxx
xx
RandomMulti
x


x
RandomSingleFromList
x


x
Redirectxxxx
x
SelectFirstN






SelectNxxxx
x
SelectOneFromListxxxxxx
SelectRandomNxxxx
x
SelectTopXFromRows
x


x
SingleAutoCode
x


x
Substr
x




Sumxxxx
x
TimeAdj
x


x
TimeDiffHxxxx
x
TimeDiffSecondsxxxx
x
ToMax




xx
ToMin




xx
UrlEncode
x

x

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.