Prefilling value, variable type

More
1 year 1 month 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?

Note: If I asked something and forgot to say version, I am using LS 4.x.
The topic has been locked.
More
1 year 1 month 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!

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.
More
1 year 1 month 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.

Note: If I asked something and forgot to say version, I am using LS 4.x.
The topic has been locked.
More
1 year 1 month 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.

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.
More
1 year 1 month 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
The topic has been locked.
More
1 year 1 month 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.

Note: If I asked something and forgot to say version, I am using LS 4.x.
The topic has been locked.
More
1 year 1 month 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 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.
More
1 year 1 month 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?

Note: If I asked something and forgot to say version, I am using LS 4.x.
The topic has been locked.
More
1 year 1 month 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
The topic has been locked.
More
1 year 1 month 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.

Note: If I asked something and forgot to say version, I am using LS 4.x.
The topic has been locked.
More
1 year 1 month 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
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now