Difference between revisions of "SetVariableExpressionEnd"

From LimeSurvey Manual

Line 1: Line 1:
{{Alert|This feature is currently implemented in beta version of LimeSurvey.}}
== Usage ==  
== Usage ==  

Revision as of 17:01, 19 February 2020

 Hint: This features is available starting in version 4.0.0


This event happen when ExpressionScript is constructed. It allow to update know variables array by expression.


  • surveyId : the related survey id
  • language : the related language
  • knownVars : the current known Variables by expression.
  • newExpressionSuffixes : and empty array by default. To be added as expression suffix (like .question, .NAOK etc …)

Possible output

  • knownVars : The new knowVars

Some detail of knowVars

knowVars are array of variables know by expression manager. Key are the variables.

  Update knowVars in your plugins can break LimeSurvey core functionnality.

LimeSurvey core have 2 types of variables for knowVars :

  • Value fixed by template or survey or current view : SID, SURVEYURL, QID …
  • Value from response of the user.

Fixed variables are stored as

$knownVars[$variable] = array(
    'code' => // the static value for the variable
    'type' => // ''
    'jsName_on' => // ''
    'jsName' => // ''
    'readWrite' => // 'N' - since these are always read-only variables

Dynamic variables are stored as

$knownVars[$sgqa] = array(
    'jsName_on' => // the name of the javascript variable if it is defined on the current page - often 'answerSGQA'
    'jsName' => // the name of the javascript variable when referenced  on different pages - usually 'javaSGQA'
    'readWrite' => // 'Y' for yes, 'N' for no - currently not used
    'hidden' => // 1 if the question attribute 'hidden' is true, otherwise 0
    'question' => // the text of the question (or subquestion)
    'qid' => // the numeric question id - e.g. the Q part of the SGQA name
    'gid' => // the numeric group id - e.g. the G part of the SGQA name
    'grelevance' =>  // the group level relevance string
    'relevance' => // the question level relevance string
    'qcode' => // the qcode-style variable name for this question  (or subquestion)
    'qseq' => // the 0-based index of the question within the survey
    'gseq' => // the 0-based index of the group within the survey
    'type' => // the single character type code for the question
    'sgqa' => // the SGQA name for the variable
    'ansList' => // ansArray converted to a JavaScript fragment - e.g. ",'answers':{ 'M':'Male','F':'Female'}"
    'ansArray' => // PHP array of answer strings, keyed on the answer code = e.g. array['M']='Male';
    'scale_id' => // '0' for most answers.  '1' for second scale within dual-scale questions
    'rootVarName' => // the root code / name / title for the question, without any subquestion or answer-level suffix.  This is from the title column in the questions table
    'subqtext' => // the subquestion text
    'rowdivid' => // the JavaScript ID of the row identifier for a question.  This is used to show/hide entire question rows
    'onlynum' => // 1 if only numbers are allowed for this variable.  If so, then extra processing is needed to ensure that can use comma as a decimal separator

About Expression Suffixes

When ExpressionScript get a variables, if there are no suffix, default one is code. If you want to add new suffixes : you can add it in newExpressionSuffixes. Currently only «Fixed» suffix is allowed. Value of the suffix is same in PHP and javascript.

Sample plugins