Expression questions

With expression questions you can calculate a value based on previously answered questions. This tutorial will explain how to use the expressions questioon and inbuild function

Using question results

With an expression you use previously answered questions results to get a new result, to access these results you can use:

 

{questionname} Access the value of a single input question
{dynamicpanelname[index].questionname} Access the question value inside the panel dynamic, where index is zero-based
{matrix[index].columnname} Access the question value for matrix dynamic, where index is zero-based
{row.columnname} Access the row value in a matrix multiple choice expression question
{questionname-total.columnname} Access the total value in a matrix multiple choice question

 

Using functions

The format for using function is: functionName(Argument1, Argument2, .... , ArgumentN), and agrument can also be a function, explained in the section below.

 

iif

 

iif(condition: expression, true_value: any, false_value: any): any
Returns true_value if the given condition is true and false_value if the condition is false.
Example: iif({question1} + {question2} > 20, 'high', 'low')

age

 

age(birthDate: any): number
Returns the age according to the date of birth
Example: "age({date_of_birth})"

currentDate

 

currentDate(): Date
Returns the current date.
Example: "currentDate()"

today

 

today(days_to_add: number): Date
Returns the current date or a date calculated using the parameter which specifies the number of days to be added to the current date.
Examples: "today()" returns todays date; "today(2)" returns day after tomorrow; "today(-1) returns yesterdays date"; etc

getDate

 

getDate(question_name: expression): Date
Returns the specified question's date value.
Example: "getDate({Birthday})"

weekday

 

weekday(date?: Date): Number
Returns the day of the week for a given date as a value from 0 (Sunday) to 6 (Saturday).
Example: "weekday({Birthday})"

day

 

day(date?: Date): Number
Returns the day of the month for a given date.
Example: "day({Birthday})"

month

 

month(date?: Date): Number
Returns the month for a given date.
Example: "month({Birthday})"

year

 

year(date?: Date): Number
Returns the year for a given date.
Example: "year({Birthday})"

diffDays

 

diffDays(date_from: any, date_to: any): number
Returns the absolute number of days between two dates.
Example: expression: "diffDays({start_date}, {end_date}) > 30"

differenceDays

 

differenceDays(date_from: any, date_to: any): number
Returns the number of days between two dates.
Example: expression: "diffDays({start_date}, {end_date}) > 30"

sum

 

sum(par1: number, par2: number, ...): number
Returns the sum of the arguments.
Example: "sum({total_one}, {total_two})"

max

 

max(question_one: number, question_two: number, ...): number
Returns the largest value from a list of the arguments
Example: "max({question_one}, {question_two})"

min

 

min(question_one: number, question_two: number, ...): number
Returns the largest value from a list of the arguments.
Example: "min({question_one}, {question_two})"

avg

 

avg(question_one: number, question_two: number, ...): number
Returns the average value of the passed arguments.
Example: "avg({question_one}, {question_two}, {question_three})"

sumInArray

 

sumInArray(question_name: expression, property_name: string): number
Returns the sum of values in a array from the question property; the question and its property are referenced by their names.
Example: "sumInArray({matrixdynamic_one}, 'total') > 1000"
;

maxInArray

 

maxInArray(question_name: expression, property_name: string): number
Returns the maximum of all values in an array specified by a property of a matrix question.
Example: "maxInArray({matrixdynamic_one}, 'quantity') > 20"

minInArray

 

minInArray(question_name: expression, property_name: string): number
Returns the minimum of all values in an array specified by a property of a matrix question.
Example: "minInArray({matrixdynamic_one}, 'quantity') > 5"

avgInArray

 

avgInArray(question_name: expression, property_name: string): number
Returns the average of all values in an array specified by a property of a matrix question.
Example: "avgInArray({matrixdynamic_one}, 'quantity') > 10"

displayValue

 

getTextValue(question_name: string): string
Returns the text value of a questions.
Example: "getTextValue('question1'}) "

getUser

 

getUser(): string
Returns the username of the current user.
Example: "getUser() "

getRole

 

getRole(): string
Returns the role of the current user.
Example: "getRole() "

countInArray

 

countInArray(question_name: expression, property_name: string): number
Returns the total number of items of all values in an array specified by a property of a matrix question.
Example: "countInArray({matrixdynamic5}) > 10"

countAnswers

 

countAnswers(survey_name.questionnaire_name.question_name: string, question_answer: string or expression): number
Returns the total number of questions for which the answer is equal to the question answer. 
Example: "counAnswer("stockcontrol.stock.item", {stockitem})" 

Example: "counAnswer("stockcontrol.registration.item", {stockitem})" When using the registration of the survey

 

 

Boolean expressions

Boolean expressions return a true or false value, some examples are shown below:

 

"{age} >= 21" Returns true if the age is 21 or higher
"{age} >= 21 and {age} < 65" Returns true if the age is 21 or larger and smaller than 65
"!({age} >= 21 and {age} < 65)" Returns false if the age is 21 or larger and smaller than 65
"{name} = notempty" Returns true if the name question is not empty
"{name} = empty" Returns true if the name question is empty
"{country} = ['France','Spain']" Returns true if the country question selects only France and Spain (checkbox)
"{country} = contains 'Spain'" Returns true if the country question selects at least Spain (checkbox)

 

Operators:

AND Logic AND function, both conditions need to be true
OR Logic OR function, at least one conditions needs to be true
! Logic NOT function, inverse the result
notempty Is question not empty?
empty Is question empty?
contains Does question contain a value?

 

© Denkami 2024 | 18 Kapumpe Rd, Lusaka, Zambia | +260 962 401 869 | admin@denkami.com