Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Insert answer from previous survey

Insert answer from previous survey 3 years 6 months ago #90931

  • stevage
  • stevage's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Hi,
I need to be able to insert a participant's answer to a question in a previous survey. I'm running into a few problems:

1) It seems very hard to actually insert the {INSERTANS:123X4X5} code. Pushing the "LimeSurvey replacement field properties" didn't show it, so I ended up having to insert a dummy field, switching to Source view, then edit it. (So maybe I'm doing something wrong).

2) It doesn't work anyway. I did this:

- participants self-register for survey #1, complete the survey, get a token.
- I selected one of their email addresses, created an entry in the token table for survey #2, then manually copy-pasted the token from survey #1
- invited the participant
- participant logs in, but the question shows up like this:

Your answer last time: INSERTANS:751966X3X4

(The INSERTANS bit is in red text on a brown background with a red border, with mouseover text "Undefined variable").

Is what I'm trying to do definitely possible? Where am I going wrong?

Also, I can't see any way to launch the Expression Manager? I'm using 2.00+, Build 121121.
The administrator has disabled public write access.

Insert answer from previous survey 3 years 6 months ago #90947

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6129
  • Thank you received: 1360
  • Karma: 535
You cannot use INSERTANS to access answers from other surveys.

Solutions may be:

1) Place the answer(s) in the token table and then use {TOKEN:ATTRIBUTE_1}

2) Prefilling survey answers using the survey URL
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Insert answer from previous survey 3 years 6 months ago #90987

  • stevage
  • stevage's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Thanks for that. I've managed to make Solution 2 work, so I think my final workflow ends up like this:

1) Create and run survey #1 as normal (users self register, create tokens, etc)
2) Create survey #2:
- new tokens table
- extended attribute for every answer you want to reuse from survey #1
- to refer to a participant's previous answer, you insert {TOKEN:ATTRIBUTE_4}
- to pre-fill an answer, you add this (in "source" mode):
<script>
$(document).ready(function()
{
$("#answer168948X4X5").text('{TOKEN:ATTRIBUTE_4}');
});
</script>

where "168948" is survey #2's id, 4 is the group id, and 5 is the question ID.
3) Export answers from survey #1
4) Export the (blank) tokens table from survey #1 as CSV, to get the header structure.
5) Use Excel magic to populate the CSV file in 4 with answers from 3
6) Import the freshly populated CSV file as tokens for survey #2
7) Activate the survey, send out invitations, hurray!

The workflow is a little bit messy, but it doesn't involve modifying any code, so I'm happy.

(I haven't actually tested steps 3, 4, 5 and 6 - but that should work, right?)
The administrator has disabled public write access.

Insert answer from previous survey 3 years 6 months ago #90996

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6129
  • Thank you received: 1360
  • Karma: 535
Yep, that should do the trick.

I'm sure that you could do some PHP magic to automate steps 3-6 but, sadly, I'm not strong in PHP.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.228 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form