Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Something's still off, not sure I understand

Zachary,
Thanks for your response. However, I think there may have been a misunderstanding. My pass-in field is QG and the parent list is named GenderO.  Therefore, I was guessing that I should swap GenderO and QG in your code - both spots. However, I'm still getting the same Error 132. Thoughts?

Here's my modified code:
Begin Unverified Perl

# Parameters

my $input = GETVALUE('QG');
my $index = 0;
 
my $flag = substr($input, $index, 1);
if ($flag == 1) {
    ADD($GenderO, 1);
}
else {
    ADD($GenderO, 2);
}

End Unverified

In the Admin module, the error references  GenderO ...
System Error:
Global symbol "$GenderO" requires explicit package name at (eval 88) line 8, line 56. Global symbol "$GenderO" requires explicit package name at (eval 88) line 11, line 56.

I'm not sure what "explicit package name" means but that seems to be the problem.

Regarding your alternative suggestion, that was my original plan. However, Mailchimp only allows 255 characters max for links and when we tried to pass-in Panelist#, Project#, Age, Education, State, County, Zip, plus those much longer versions for Gender and Ethnicity we had about 284. So, using strings for Gender and Ethnicity is necessary.

Again, I appreciate your assistance on this problem.
asked Jul 27 by MMidghall (225 points)
The Add function needs the name of a list.  If you want to hard code in the name of the list, it would look something like this:

ADD('GenderO', 1);


Previously, you put the list's name in a variable.  That could also work.

my $plist = 'GenderO';

ADD($plist, 1);
Thanks again, Zachary. Still have one issue that I can't resolve. Instead of storing 1's or 0's the code is storing 1's or 2's. I tried using ADD LISTLABEL ('GenderO', 1)  instead but that generates an error. What do you suggest?
What do you mean by "storing"?  You mean when you look at the constructed list item in the respondent data?
Yes. I'd like my individual response item lists for Gender and Ethnicity to mirror what is obtained from asking the questions in the survey (which we do for an outside panel.) This way I can more easily merge the data after fielding.

1 Answer

0 votes
That's what constructed lists are: just a subset of items in a predefined list.  I wouldn't look at them as a way of "storing" arbitrary data.

What I was suggesting a week ago was to create a series of other pass-in fields that we can use to record each data point.  Give them all a shared base name with an incrementing number at the end, like "GenderVar1", "GenderVar2", "GenderVar3", etc.  Then we can place this script into our survey to store the values we want in them:

[% Begin Unverified Perl
# Settings
my $inputVariable = 'GenderO';
my $outputVariableBaseName = 'GenderVar';

# Run
my @codes = split(//, GETVALUE($inputVariable));
for (my $i = 0; $i < scalar(@codes); $i++) {
    SETVALUE($outputVariableBaseName . '_' . ($i + 1), $codes[$i]);
}
End Unverified %]
answered Aug 2 by Zachary Platinum Sawtooth Software, Inc. (212,550 points)
Not sure I follow above ...
1. GenderO is my parent list (1,0), so line 3 should use 'QG' (my pif label), right?
2. Line 9: Is SETVALUE correct? ... or should it be GETVALUE?
3. However, if this method requires 6 pif's for Gender and 8 for Ethnicity - the number of multi-select question response options on the registration form - than it requires too many characters in the URL. MailChimp,  who we use for email invitations to Panel #1, only allows 255 max characters in links. This is the reason I'm going to pass-in strings for Gender and Ethnicity.

I'm going to just use the less than ideal 1's and 2's that are stored in the data file for my constructed MaleO, FemaleO, etc. AsianO, CaucasianO, etc lists. After fielding I'll replace the 2's with 0's so they mimic what Panel #2 respondents generate in the regular demographic questions (which Panel #1 will now bypass.) This is a monthly survey. I'll try to get the desired 1's and 0's for my constructed lists in the September survey.

Thanks for your time and efforts. Wish I had a stronger understanding of Perl to take better advantage.
Yes, line 3 is meant to be the pass-in field.  Nothing outside of the "Settings" area should have to be touched.

These pass-in fields aren't actually required on the URL.  We're just using them to add more fields to our survey to save values to.
Oh ... I will try this for our September Survey. So, all I would change is the $i=0 to $i=1 for GenderVar2, $i=2 for GenderVar3, etc. and these are all pass-in-field labels? Should I insert all the scripts in a hidden question, or is there a better place?

Thanks for sticking with this problem!
There is only one script.  Nothing outside of the "Settings" area should have to be touched.  Run the script anywhere after the start page and before you need the values.
...