- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Accessing Expression Manager-variables dynamically
- Hananami
- Topic Author
- Offline
- New Member
Less
More
3 years 9 months ago #202683
by Hananami
Accessing Expression Manager-variables dynamically was created 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:
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):
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!
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:
Code:
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):
Code:
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!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
3 years 9 months ago #202687
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Accessing Expression Manager-variables dynamically
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.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
3 years 9 months ago #202712
by DenisChenu
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.
Replied by DenisChenu on topic Accessing Expression Manager-variables dynamically
Right,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.
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
The topic has been locked.
- Hananami
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
3 years 9 months ago #202783
by Hananami
Replied by Hananami on topic Accessing Expression Manager-variables dynamically
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.
The topic has been locked.