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.
| Script | Description | Parameters | Examples | 
| AdjustTime, TimeAdj | Modify 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_TimeNowH | Returns 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_TimeStartF | Returns 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 | |||
| AutoCode | It 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". | |||
| CodeLess1 | Creates a range, typically to be used single-choice question from 1 to one less than the code | script:CodeLess1(code) | script:CodeLess1(10) | 
| Result: 1:9 | |||
| CodeUpToN | Creates a range, typically to be used on numeric questions. | script:CodeUpToN(code) | script:CodeUpToN(10) | 
| Result: 0:10 | |||
| CodeXor | Typically 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. | |||
| Concat | Concatenes any number of values | script:Concat(v1,v2,v3...) | script:Concat(\@sys_date,' Calender') | 
| Result: 20200101 Calendar - if \@sys_date=20200101 | |||
| CreateShortURLKey | Returns the 8 number/characters that should go after https:\\url.quenchtec.net | script: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 | |||
| CurrentAge | Calculates the age based on yearBorn and this year | script:CurrentAge(yearBorn,thisYear) | script:CurrentAge('1990',\@sys_year) | 
| Result:If the current year is 2020, then returns 30. | |||
| Diff | Calculates the difference between value1 and value2, noAnswerValue is substituted if the referenced question has no answer | script:Diff(value1,value2,noAnswerValue) | script:Diff(\Number1.a.1,\Number2.a.1,0) | 
| Diff0 | Computes 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 | |||
| DiffNeg | Computes 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, | |||
| Div | Returns the division of any number of values | script:Viv(value1,value2,value3...) | script:Min(100,10,2) | 
| Result:5 | |||
| Echo | Used to just return the values, typically for debugging | script:Echo(value1,value2,value3...) | script:Echo(\BrandsKnown.a,'hello') | 
| Result:Any values selected from \BrandsKnown followed by "hello" | |||
| EmailN | Returns 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 | ||
| FormatString | Build 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}&,\@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 | |||
| FromTo | Set 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" | ||
| HashSum | Creates a range, typically to be used on numeric questions that represents a sum | script:HashSum(sumValue) | script:HashSum(100) | 
| Result:#100 | |||
| HttpReq | HttpReq - Send a HttpRequest using "GET" method | script: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 | |
| IsEqual | Compare 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) | |||
| Join | Join any number of values with the separator joining each value | script:Join(separator,v1,v2,v3....) | script:Join('-','value1','value2') | 
| Result:value1-value2 | |||
| LengthOf | Returns the length of the value/string | script:LenghtOf(value) | |
| LIndex | Returns 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 | |||
| Max | Returns the maximum value of any number of values | script:Max(value1,value2,value3...) | script:Max(4,7,8,1) | 
| Result:8 | |||
| MaxIndex | Returns 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. | |||
| Min | Returns the minimum value of any number of values | script:Min(value1,value2,value3...) | script:Min(4,7,8,1) | 
| Result:1 | |||
| MinIndex | Returns 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. | |||
| Mult | Returns the multiplication of any number of values | script:Mult(value1,value2,value3...) | script:Mult(1,2,3) | 
| Result:6 | |||
| Multi Answer Count | Calculates the amount of answers in a particular question | script:multiAnswerCount(Questionlabel) | script:multiAnswerCount(Q1) | 
| Quarter | Returns the quarter, based on the date | script:Quarter(date) | script:Quarter(\@sys_date) | 
| Result:3 if sys_date=202000701 | |||
| RandomMulti | Typically used to create a series of random numbers | script: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 | |||
| RandomSingleFromList | Pick 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 | |||
| Redirect | The 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" | |||
| SelectFirstN | Typically used to select a codes from a multi-choice question | script: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 | |||
| SelectN | Pick the "Nth" value from a multiplechoice question | script:SelectN(MultipleChoiceQuestion,valueToPick) | script:SelectN(\Brands_Known.a,2) | 
| Result: Returns the second code the respondent gave to question BrandsKnown | |||
| SelectOneFromList | Returns 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 | |||
| SelectRandomN | Typically used to select a number of codes from a multi-choice question | script: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 | |||
| SelectTopXFromRows | Typically 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 | |||
| SingleAutoCode | Looks 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 | |||
| Substr | Returns a 1 based substring of string | script:Substr(string,start,length) | script:Substr(\open.a,1,2) | 
| Result:Returns the first two characters of question \open.a | |||
| Sum | Calculates the sum of 2 to 15 numbers. If any number is non-numeric it is set to 0 | script:sumN(N=2-15) | script:sum8(\Q1,\Q2,\Q3,\Q4,\Q5,\Q6,\Q7,\Q8) | 
| This will automatically create the sum of 8 questions | |||
| TimeDiffH | Computes 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 | |||
| TimeDiffSeconds | Calculate the time difference between two paramters in seconds | script:timediffseconds(starttime,endtime) | script:timediffseconds(\StartTime.a.1,\EndTime.a.1) | 
| ToMax | Creates a range, typically to be used on numeric questions. "1" is automatically added to the "start" value | script:ToMax(start,end) | script:ToMax(1,10) | 
| Result:2:10 | |||
| ToMin | Creates 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 | |||
| UrlEncode | Url encode any text string to make sure it can be passed as a parameter in a URL request | script:UrlEncode(value) | script:UrlEncode('myep1=somev1&nationalname=Bjørn') | 
| Result:myep1%3Dsomev1%26nationalname%3DBj%C3%B8rn | 
| Answer control | |||||||
| Functions | Question filter | Automatically fill in answer | filter a-z | row filter | Redirect on exit | Masking | Validation | 
| AdjustTime | x | x | |||||
| AdjustTimeNowH | x | x | |||||
| AdjustTimeStartF | x | x | |||||
| AutoCode | x | x | x | x | x | ||
| CodeLess1 | x | x | |||||
| CodeUpToN | x | x | |||||
| CodeXor | x | x | x | ||||
| Concat | x | x | x | x | |||
| CurrentAge | x | x | x | x | |||
| Diff | x | x | x | x | x | x | |
| Diff0 | x | x | x | x | x | x | |
| DiffNeg | x | x | x | x | x | x | |
| Div | x | x | x | x | x | x | |
| Echo | x | x | x | ||||
| FormatString | x | x | |||||
| FromTo | x | x | |||||
| HashSum | x | ||||||
| HttpReq | x | x | x | x | x | x | x | 
| IsEqual | x | x | x | x | |||
| Join | x | x | x | ||||
| LengthOf | x | x | x | x | x | ||
| LIndex | x | x | |||||
| Max | x | x | x | x | x | ||
| MaxIndex | x | x | |||||
| Min | x | x | x | x | x | ||
| MinIndex | x | x | |||||
| Mult | x | x | x | x | x | ||
| MultiAnswerCount | x | x | x | x | x | ||
| Quarter | x | x | x | x | x | x | |
| RandomMulti | x | x | |||||
| RandomSingleFromList | x | x | |||||
| Redirect | x | x | x | x | x | ||
| SelectFirstN | |||||||
| SelectN | x | x | x | x | x | ||
| SelectOneFromList | x | x | x | x | x | x | |
| SelectRandomN | x | x | x | x | x | ||
| SelectTopXFromRows | x | x | |||||
| SingleAutoCode | x | x | |||||
| Substr | x | ||||||
| Sum | x | x | x | x | x | ||
| TimeAdj | x | x | |||||
| TimeDiffH | x | x | x | x | x | ||
| TimeDiffSeconds | x | x | x | x | x | ||
| ToMax | x | x | |||||
| ToMin | x | x | |||||
| UrlEncode | x | x | |||||