Recoding questions using FlowScript

Compatibility:IdSurvey 6IdSurvey 7
X

It is often necessary to recode answers for an easier analysis or to make it easier to set quotas or any display conditions of the questionnaire.

A common use is that of asking the age of the respondent in a numeric format when it is necessary to record the data as age group, in order to set the quotas in an easier way.

If the respondent answers the question indicating an age below 18, we want the custom field named “Group” populated with 1-17. If the respondent indicated an age between 18 and 29, the field will be populated with 18-24 and so on.

In order to do that, you have to add a FlowScript from the settings of the page.

Let’s start with a first condition and the related instruction:

if( [Q1] <= 17 ) {Group}=‘1-17';

If the open answer given to question Q1 is below or equal to 17, the field Group will be populated with 1-17. 

Let’s enter other conditions for each group.

if( [Q1] >= 18 && [Q1] <= 29 ) {Group}=’18-29';

If the open answer given to question Q1 is below or equal to 17 and below or equal to 29, the field Group will be populated with 18-29. 

Example of the entire script:

if( [Q1] <= 17 ) {Group}='1-17';   
 if( [Q1] >= 18 && [Q1] <= 29 ) {Group}='18-29';    
if( [Q1] >= 30 && [Q1] <= 49 ) {Group}='30-49';    
if( [Q1] >= 50 && [Q1] <= 69 ) {Group}='50-69';    
if( [Q1] > 70 ) {Group}='over70';

IdSurvey will process the script during the saving process of the page.

Notes

  • You must enter a semicolon at the end of each instruction.
  • You can enter multiple instructions by putting them in curly brackets. For example:
  • { {Group}='1-17';OT( ); }

     Field Group will be populated with 1-17 and you are sent “out of target”. 

  • To retrieve an open answer in a question you have to put the code of the question in square brackets.
  • It is essential to use single quotes to write the string 18-29. Without single quotes the system would process it as an arithmetic operation, for example 18 minus 29.