Prefilling value, variable type

More
1 month 3 weeks ago #191458 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?

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 month 3 weeks ago #191463 by gabrieljenik
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!

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191479 by Jmantysalo

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.

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191481 by gabrieljenik
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.

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191483 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191486 by Jmantysalo

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.

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191501 by holch
{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'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191530 by Jmantysalo
Thanks, {TOKEN:ATTRIBUTE_1} works. And now hopefully the last question: how do I refer to that attribute from api call add_participants?

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191545 by jelo
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

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191552 by Jmantysalo
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.

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #191554 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: Jmantysalo

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!