Have an idea?

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

Listlabel command inside Perl

I have two pass-in variables that are populated in the survey.
I am trying to create a question that displays text for  one or the other pass-in variables based on previous answers. I am trying the following code and nothing is displaying.

[% Begin Unverified Perl
if    (GETVALUE("CURRCOMM1")    >=    1)
    {
        return    LISTLABEL("AAMode1DisplayList","CURRENTMODE");
    }
    else
    {
        return    LISTLABEL("AAMode1DisplayList","PRIMARYMODE");
    }
End Unverified %]


It looks like the "LISTLABEL" command does not work within perl as when I test it there is no text.  Is there some way to accomplish this or do I need to create two questions?
asked Aug 13 by Nwiggin Bronze (855 points)

1 Answer

0 votes
ListLabel expects its second parameter to be a number, indicating which item from the list it is meant to return.  If "CURRENTMODE" and "PRIMARYMODE" are your pass-in variables which contain numeric values, then I think this is what you're after:

[% Begin Unverified Perl
if (GETVALUE("CURRCOMM1") >= 1)
{
    return LISTLABEL("AAMode1DisplayList", GETVALUE("CURRENTMODE"));
}
else
{
    return LISTLABEL("AAMode1DisplayList", GETVALUE("PRIMARYMODE"));
}
End Unverified %]
answered Aug 13 by Zachary Platinum Sawtooth Software, Inc. (153,100 points)
Thanks, I figured it out (though slightly different)  about 2 minutes before your reply.  Where you use "GETVALUE", I used "VALUE" and it appears to work.  To your knowledge, is there any reason why I should use one or the other (GETVALUE vs VALUE)?

    [% Begin Unverified Perl
if    (GETVALUE("CURRCOMM1")    >=    1)
    {
        return    LISTLABEL("AAMode1DisplayList",VALUE("CURRENTMODE"));
    }
    else
    {    
        return    LISTLABEL("AAMode1DisplayList",VALUE("PRIMARYMODE"));
    }
End Unverified %]
Value and GetValue are identical in behavior.  I just prefer the latter as its name is more specific and pairs nicely with its sibling function SetValue.
...