getPrevRepeatValue()

Fetch a value from the previous non-deleted row within the same instance, where the question of interest is entered. This function is available for repeating forms and repeating sections of two-section forms.

Tip:

You can use this function to get the value form a previous row for either the same or a different question.

Syntax

getPrevRepeatValue('ruleVariable', [isNullConsidered])

Parameters

Note:

It is allowed to reuse variables passed into this function elsewhere in the rule expression, however you must add the variable as a parameter using single quotes.
Parameter Required/Optional Description
ruleVariable Required Name of the rule variable to get its value, passed in using single quotes. The rule variable is defined for a specific visit, form and item.
isNullConsidered Optional Boolean parameter to indicate if null values should be included in the search.
  • true - previous value is returned even if it is null. This parameter is set to true by default.
  • false - only returns value if it is not null.

    When false is set for this parameter, system will keep looking backwards until either it finds the closest not-null value or the entirety of rows have been searched.

Return value

Returns the value for the specified item in the immediate previous row. Depending on the optional parameter configuration, whether null is considered or not, can return any value (including null) from the immediate previous row, or the closest previous not null value, if the immediate previous row is null for the given item.

If the variable is a choice control (checkbox, radio or drop-down), the return value is the string in JSON format:
("[{\"value\":\"3\",\"label\":\"TestLabel\"}]")

Tip:

This can be parsed using JSON.parse(result) or the helper function parseChoice(result).

Examples

Example 3-59 Get value of a given variable in the previous row

var prevValue= getPrevRepeatValue('vValue', false); //returns the first previous not null value
var prevValue= getPrevRepeatValue('vValue');  //returns the first previous value