Have an idea?

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

Setting pass-in variable value based on perl

This is an extension of a question I have asked earlier. In short,  if we pulled in the correct city/state from the zip code it displays that value. if we got it wrong then I pull in a concatneated version. This works well, but I'm having to use the original coding a lot and it is cumbersome.

So, I'm trying something new.  I start with trying to set the value of my passin variable NEWCITYSTATE. That is shown in this first bit of code below.  Then I want to be able to recall the value simply by going [% NEWCITYSTATE %].

While I'm not getting any errors when running the script below, nothing displays when I try to display [% NEWCITYSTATE %].  Yes, this is a text variable.

[% Begin Unverified Perl
#setting string for concatenation
my $tempcity = GETVALUE("LOC1_r1_c1");
my $tempstate = LISTLABEL("STATEList", GETVALUE("LOC1_r1_c2"));
my $newloc    = $tempcity    .    ', '    .    $tempstate;

#Condition for displayed text
if    (GETVALUE("CorrectCity")    ==    2)
    {
        SETVALUE("NEWCITYSTATE",$newloc);
    }
    
End Unverified %]
asked Aug 25, 2020 by Nwiggin Bronze (1,310 points)
Where are you trying to display it, is it on same page, where you are applying SetValue?
In this case, I am running the SetValue  early and then displaying the text all throughout the survey on a variety of pages.

I'm looking for a more efficient way of doing it rather than running this code all the time.

[% Begin Unverified Perl
#setting string for concatenation
my $tempcity = GETVALUE("LOC1_r1_c1");
my $tempstate = LISTLABEL("STATEList", GETVALUE("LOC1_r1_c2"));
my $newloc    = $tempcity    .    ', '    .    $tempstate;

#Condition for displayed text
if    (GETVALUE("CorrectCity")    ==    1)
    {
        return $newloc;
    }
    elsif    (GETVALUE("CorrectCity")    ==    2)
    {
        return LISTLABEL("CITYSTATEList", GETVALUE("CITYSTATE"));
    }
End Unverified %]
[% NEWCITYSTATE %] should display the text. May be the SetValue is not woking, not sure. Please check if you are having something in the variable by data view/download.

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...