Accessing Expression Manager-variables dynamically

More
4 weeks 2 days ago #202683 by Hananami
Hello forum,

I am currently trying to enable a dataflow between limesurvey and our database and vice versa.
Inside the database we have a table, from where I determine which questions are to be asked and create an array of
the Question- Codes (for example questions_array = ["Q1","Q2_A1","Q4"]).

With this array loaded to the survey, I would like to
1) hide those (sub-)questions not in the array and
2) Get an array of the answers for these questions at the end of the survey


Here I face multiple problems for which I have not found a satisfactory answer yet:

--> for 1) For hiding questions in a group that are not in the questions_array, I need to get the codes of the questions in this group. I would next check, whether some are not in the questions_array and then hide the corresponding question-div. [The code would be written inside the group-description]

something like:
 
questions_array = /*..questions to be done, load from database..*/
question_codes_in_group = /*.. somehow get the question-codes of the questions in this group..*/
question_sgqa_in_group= /*..somehow get the SGQA of the questions in this group..*/
num_questions_in_group = questions_codes_in_group.length;
 
for(i=1; i<num_questions_in_group; i++)
{
    if(!questions_array.includes(questions_group[i]))
    {
         //Question not to be asked
         $("#question"+question_sgqa_in_group[i]).hide();
 
         //-->when matrix??
         $("#javatbd"+question_sgqa_in_group[i]).hide();
    }
}

I know the question_codes_in_group and question_sgqa_in_group could be hardcoded into the survey, but I thought of it as redundant and a bit dirty.


--> for 2) Is there a way to get the answers from the EM via the variable name stored in a string?
I know that this following code does not work, but it is essentially what I want to do (at the very end of the survey):
 
questions_array = /*..questions to be done, load from database..*/
...
 
for(i=1; i<num_questions; i++)
{
    answer_array[i] = {questions_array[i]};
}
 
/*... upload answer_array to database..*/
 

Is there maybe a way to gain access to the EM-Variables via functions or any other way?

Any help is very much appreciated, thank you!

Please Log in to join the conversation.

More
4 weeks 2 days ago #202687 by tpartner
I don't see a way to do this. Expression Manager variables are rendered server-side and cannot be rendered dynamically client-side.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
4 weeks 2 days ago #202712 by DenisChenu

tpartner wrote: I don't see a way to do this. Expression Manager variables are rendered server-side and cannot be rendered dynamically client-side.

Right,

In 4.X (sorry … can't add this feature in 3.X …) : you can use manual.limesurvey.org/SetVariableExpressionEnd event.

In 3.X : get inspiration by hacking Expression Manager (create yourself the session) : gitlab.com/SondagesPro/SurveyAccess/part...nSurveyFill.php#L410

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.
The following user(s) said Thank You: Hananami

Please Log in to join the conversation.

More
4 weeks 19 hours ago #202783 by Hananami
Thank you for the answer. Since I need a quick fix for now, I will go with hardcoding the IDs into the survey but might come back to this idea later on.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now