Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Is it possible to dynamically generate values for questions from our database?

  • konstantink1
  • konstantink1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 months ago #226098 by konstantink1
Hello everyone, I'm a frontend developer and very new to the LimeSurvey, so starting to look into possibility of using LimeSurvey for the needs of the company I'm working for.

Basically our team is looking to use cloud-based LimeSurvey solution and majority of questions can be set up via LimeSurvey interface, however there are couple questions where options have to be generated dynamically depending on a client's id who is filling out the survey.

In a nutshell, we have a database that will store a list of values for the questions and it will dynamically update and I need to show those values in a dropdown of our LimeSurvey set up. Is there any LimeSurvey API that could be used to retrieve the questions dynamically from our server's database? Is it something generally possible to implement - to hook up the LimeSurvey questionnaire to our database values to dynamically generate options?

In case if it is important the data is stored in AWS Redshift and if it impossible to do queries directly I could possibly set up endpoints in our Node.JS (Express) Server to serve as a layer between LimeSurvey and our database in AWS Redshift

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226113 by tpartner
In general, all answer options for single-choice questions must be defined in the LimeSurvey admin interface. You cannot dynamically add an option to a list-dropdown question. It must exist in the answers table or LS will reject it.

I am not a plugin expert but that might be a possible route.

A possible workaround might be:

1) Make an AJAX call to a remote file that queries the your database and returns the answers for a given respondent.
2) Use JavaScript to create a select (dropdown) element.
3) Write the selected answer codes (and/or labels) into LimeSurvey short-text questions.

A downside to this is that you would not get charts for those questions in the core statistics view. (which I never use anyway :) )

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu, konstantink1

Please Log in to join the conversation.

  • konstantink1
  • konstantink1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 months ago #226202 by konstantink1
Thank a lot for your answer! :)

So as I understood from your answer and reading through documentation it is 2 possible solutions here:

1) To do it via creating a plugin for this purpose (I only found a plugin to create a POST request, but nothing for my needs). But as I understood it would need to be written in PHP and the LimeSurvey has to be Community Edition one installed on our server, that it cannot be cloud, would it be correct?

2) The solution with Javascript implies doing it in a runtime ( similar to this ) and setting up a script that would be inquiring our server on pageload and creating those questions with dropdowns. Do you know if it is something that is possible to implement with LimeSurvey Cloud or is it strictly for CE server?

I also found this article , I assume it is some functionality that was created within LimeSurvey for similar similar cases with need to manipulate survey variables, however seems like it doesn't have any particular API for modifying questions' options

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226217 by tpartner
1) If using the LimeSurvey GmbH servers, you will need to contact support about uploading plugins.

2) Again, if using the LimeSurvey GmbH servers you cannot place PHP files on their servers. The JavaScript AJAX code could be added to question source or in a theme file but you would need to place the AJAX target file on another server (perhaps where your database is). That server would need to support JSONP - en.wikipedia.org/wiki/JSONP .

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: konstantink1

Please Log in to join the conversation.

  • konstantink1
  • konstantink1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 months ago #226275 by konstantink1
Thank you!

So just to confirm as long as my server supports JSONP, LimeSurvey should be able to handle an asynchronous request, e.g., it will not block my async request when my server API will be requesting AWS Redshift DB (might take several seconds for it to go through)?

Also, for each of the surveys we need to have personalized answers to the questions, therefore it is desirable for this JSONP request from LimeSurvey to pass some unique parameter like organization_id, so our server could handle the request and generate appropriate dataset.

What would be the best way to implement such feature and inject this unique parameter to question source? And is it even possible?

Best regards,
Konstantin

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226276 by tpartner
95% of this is outside of LimeSurvey development so out of the scope of this forum.

I don't know anything about AWS Redshift DB so you will have to investigate that yourself.

Regarding passing an ID to your remote script, you can use the data setting in the AJAX call - api.jquery.com/jquery.ajax/

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: konstantink1

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose