Welcome to the LimeSurvey Community Forum

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

Prefilling value, variable type

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 4 months ago #191458 by Jmantysalo
Prefilling value, variable type was created by Jmantysalo
I want to add a participant to survey with API and prefill a field of type "Short free text". I tried

$new_user=array( array("email" => $email, "token" => $mycode, "validfrom" => $time1, "validuntil" => $time2, "responses" => array("aquestioncode" => "an answer")) );
$myJSONRPCClient->add_participants($sessionKey, LS_SURVEY_ID, $new_user, False);

but this does not work. The participant is added, but the question with code "aquestioncode" is not prefilled. So I suppose that the string must be converted to some other type, but to what and how?
The topic has been locked.
  • gabrieljenik
  • gabrieljenik's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 4 months ago #191463 by gabrieljenik
Replied by gabrieljenik on topic Prefilling value, variable type
Hi,

With the API you can prefill a custom token attribute.
Then in the survey you can prefill a question from the token attribute.

Thanks!

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Checkout our Reporting Solutions and our plugin shop at www.encuesta.biz .

The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 4 months ago #191479 by Jmantysalo
Replied by Jmantysalo on topic Prefilling value, variable type

gabrieljenik wrote: Hi,
With the API you can prefill a custom token attribute.
Then in the survey you can prefill a question from the token attribute.



I don't quite get this. I will have same prefilled value(s) for many tokens, so how to do that? Token can not be very long.
The topic has been locked.
  • gabrieljenik
  • gabrieljenik's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 4 months ago #191481 by gabrieljenik
Replied by gabrieljenik on topic Prefilling value, variable type
When creating the tokens, you can fill extra attributes for it.
manual.limesurvey.org/Survey_participants#Manage_attributes

Then the questions will be prefilled from those extra custom attributes.

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Checkout our Reporting Solutions and our plugin shop at www.encuesta.biz .

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 4 months ago #191483 by tpartner
Replied by tpartner on topic Prefilling value, variable type
If you have the value in a token attribute, do you really need to load it into a question, since it will be available in the data as a token attribute?

...I suppose, maybe, if you want it to appear in the LS public statistics.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 4 months ago #191486 by Jmantysalo
Replied by Jmantysalo on topic Prefilling value, variable type

gabrieljenik wrote: When creating the tokens, you can fill extra attributes for it.
manual.limesurvey.org/Survey_participants#Manage_attributes


OK, but how to refer to them? I added a custom attribute "MYDATA" and then added a question "Hello {TOKEN} with name {TOKEN:FIRSTNAME} data {TOKEN:MYDATA}, how are you doing?", but it shows TOKEN:MYDATA in red and the value I set to a test participant is not show in survey responses.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 4 months ago #191501 by holch
Replied by holch on topic Prefilling value, variable type
{TOKEN:ATTRIBUTE1} or {TOKEN:ATTRIBUTE_1} etc. (need to use the right number for your attribute, obviously.

It is not taking your name, but only the attribute_1, etc.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 4 months ago #191530 by Jmantysalo
Replied by Jmantysalo on topic Prefilling value, variable type
Thanks, {TOKEN:ATTRIBUTE_1} works. And now hopefully the last question: how do I refer to that attribute from api call add_participants?
The topic has been locked.
More
4 years 4 months ago #191545 by jelo
Replied by jelo on topic Prefilling value, variable type
You might find some inspiration from the codebase.

github.com/LimeSurvey/LimeSurvey/blob/96...rol_handle.php#L2901

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 4 months ago #191552 by Jmantysalo
Replied by Jmantysalo on topic Prefilling value, variable type
Now I got this to work. I must use "attribute_1" when adding a participant throught API, but "{TOKEN:ATTRIBUTE_1}" when referring to the value. Not so nice feature, but anyways, now everything works.

Thanks to all.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 4 months ago #191554 by tpartner
Replied by tpartner on topic Prefilling value, variable type
The reason for this is that the api uses the database column name, whereas Expression Manager uses placeholders. All token placeholders are upper-case.

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: Jmantysalo
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose