This page is an extension of the Value Assignment basic functionality, if you are not yet familiar using the value assingment, please read here.
Disclaimer: If you have a professional user license, you can use all functions described in this page. However if you are stuck, you need an extended support contract (SLA) to get our assistance. Survalyzer product support does not include value assignments. Contact our sales team to get a extended support contract.
Math.js functions
As a foundation of the value assingment element we use math.js. There are out-of-the-box functions you can use. In case, the following listed functions do not fulfill your requirements, you may search for more in math.js function reference: https://mathjs.org/docs/reference/functions.html
Arithmetic
Function | Description | Example Call | Example Result |
+ | adds terms | sum=3+2 | 5 |
– | subtracts terms | difference=3-2 | 1 |
* | multiplies terms | product=3*2 | 6 |
/ | divides terms | quotient=3/2 | 1.5 |
% | calculates the modulus | modulus=3%2 | 1 |
^ | exponentiates terms | square=3^2 | 9 |
sqrt | calculates the square root | result=sqrt(9) | 3 |
abs | calculates the absolute value | result1=abs(-5) result2=abs(5) | 5 5 |
round | rounds number to decimal | result=round(2.35,1) | 2.4 |
Statistics
Download JSON of statistics reference survey and import it into your workspace.
Function | Description | Example Call | Example Result |
sum | calculates the sum | sum(2,3,5) | 10 |
mean | calculates the mean | mean(2,3,5) | 3.3333… |
median | calculates the median | median(2,3,5) | 3 |
std | calculates the standard deviation | std(2,3,5) | 1.5275… |
variance | calculates the variance | variance(2,3,5) | 2.3333… |
min | calculates the minimum values | min(2,3,5) | 2 |
max | calculates the maximum value | max(2,3,5) | 5 |
Randomisation
Download JSON of randomisation reference survey and import it into your workspace.
Function | Description | Example Call | Survey Reference |
random | returns a real number between min (included) and max (excluded) | random(min,max) | |
randomInt | returns an integer number between min (included) and max (excluded) | randomInt(min,max) | Section 2 of randomisation survey |
pickRandom | returns a randomly chosen element out of the given list | pickRandom([var1,var2,var3]) | Section 1 of randomisation survey |
shuffle | shuffles the values of a matrix | shuffle([var1,var2,var3]) |
Texts
Download JSON of texts reference survey and import it into your workspace.
Function | Description | Example Call | Example Result |
concat | concatenates texts | concat("8005"," ","Zürich") | “8005 Zürich” |
equals | compares texts and returns either “true” or “false” | equals("8005","Zürich") | false |
contains | compares substring in texts and returns either “true” or “false” | contains("or","World") | true |
count | counts the characters of a text | count("8005 Zürich") | 11 |
[start:stop] | returns a substring, beginning at “start” and ending at “stop” (number of character) | "8005 Zürich"[1:4] | “8005” |
indexOf | returns the start position of a search string (be aware: first character is 0) | indexOf("8005 Zürich","Zürich") indexOf("8005 Zürich","Utrecht") | 5 -1 |
subset | replaces characters at defined position | subset("8000 Zurich",index(4:7),"5 Zü") | “8005 Zürich” |
Data Transformation
Download JSON of data transformation reference survey and import it into your workspace.
Function | Description | Example Call | Survey Reference |
date2number | returns timestamp (number of milliseconds) for a given date | date2number(varDate) | Section 1 of data transformation survey |
datetime2number | returns timestamp (number of milliseconds) for a given time (incl. a date) | datetime2number(varDateTime) | |
today | returns current date (data type date) | today() | Section 1 of data transformation survey |
addDays | adds number of days specified to a given date (data type date) | addDays(today(),-7) | |
parseNumber | returns integer number enclosed in text | parseNumber(varText) | Section 2 of data transformation survey |
parseReal | returns real number enclosed in text | parseReal(varText) | |
convertToString | converts given number into text | convertToString(varNumber) | Section 2 of data transformation survey |
bin | returns binary value of number (data type text) | bin(varNumber) | |
hex | returns hexadecimal value of number (data type text) | hex(varNumber) | |
csvToNumberArray | converts a CSV string into a number array (data type matrix) | csvToNumberArray('34,34,123,43') | |
csvToStringArray | converts a CSV string into a string array (data type matrix) | csvToStringArray('34, 34, 123 , 43') | |
toJSON | converts JSON string into JSON variable | toJSON(varText) |
Counters
Download JSON of counters reference survey and import it into your workspace.
Function | Description | Example Call | Survey Reference |
count_started | calculates the number of interviews with status “InProgress” | survey.count_started | Section 2a of randomisation survey |
count_completed | calculates the number of interviews with status “Completed” | survey.count_completed | Section 2a of randomisation survey |
countInterviews | calculates the number of interviews that meet the custom condition | countInterviews(customCondition) | Section 1 of counters survey |
Survey Element’s Controls
Download JSON of controls reference survey and import it into your workspace.
Function | Description | Example Call | Survey Reference |
setSurveyFieldsReadOnly | sets text fields or multiple choice checkboxes into read only mode | setSurveyFieldsReadOnly([VariableName]) | |
hide (back button) | hides the back button | BackButton("hide") | Section 2 of controls survey |
hide (next button) | hides the next button for a defined number of seconds | NextButton("hide",5) | Section 1 of controls survey |
click (next button) | automatically clicks the next button after a defined number of seconds | NextButton("click",5) | Section 1 of controls survey |
hideandclick (next button) | hides the next button for a defined number of seconds and then automatically clicks on it | NextButton("hideandclick",5) | Section 1 of controls survey |
getChoiceTitle(“[VarName]”,”[Value][Variable],[true] | returns the choice text as either in plain text format or as a comple html | title with html getChoiceTitle(“q1”, “1”) getChoiceTitle(q1, q1) // selected option title without html getChoiceTitle(“q1”, “1”, true) getChoiceTitle(q1, q1,true) // selected option |
Special Features
Download JSON of custom function and if-then-else reference survey and import it into your workspace.
Download JSON of matrixto reference survey and import it into your workspace.
Function | Description | Example Call | Survey Reference |
if-then-else statement | allows conditional executions of actions | customCondition ? thenAction : elseAction | custom function and if-then-else reference survey |
isNullOrUndefined isNull isUndefined | used in conditions to check if variable is null or undefined | isNullOrUndefined(varText) isNull(varText) isUndefined(varText) | custom function and if-then-else reference survey |
custom functions | can be used for recurrent actions | naFilter(x) = x!=0 and x!=null real3 = mean(filter([var1,var2,var3],naFilter)) | custom function and if-then-else reference survey |
list function | hides non-selected answers of a list in follow-up questions | list(choice) = answer(concat('brand_',choice.code)) == 1 ? true : false setChoicesVisibility('bestbrand',list) | JSON of list function reference survey |
getSurveyLink | generates a personal link for a certain survey | link=getSurveyLink(123) | JSON of survey link refernce survey |
matrixtoflatarray | returns a one dimensional matrix (=array) out of a multi dimensional matrix | matrixtoflatarray(varMatrix[1:end,2]) | matrixto reference survey |
matrixToHtml | generates HTML table code from a matrix variable | matrixToHtml(varMatrix) | matrixto reference survey |