Have an idea?

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

Unverified Perl - Adding values together from a numeric grid

I want to add values together to get a total from a numeric grid.  Then, based on that total, output a result.  For instance, if the value of Row 1 + the value of Row 2 = 1, output $24,000.... How do I add values together using unverified perl? Thanks.

<u>[% Begin Unverified Perl

if (VALUE("S5_r1_c1") + (VALUE("S5_r2_c1")==1 {return /$24,000;}
 
End Unverified
%]</u>
asked Jul 13 by anonymous

1 Answer

+1 vote
Your code has a mismatched parens problem; there are four open parens, but only two close ones.  In addition, you need to put quotation marks around the value you are returning because it is text.

[% Begin Unverified Perl
if (GETVALUE("S5_r1_c1") + GETVALUE("S5_r2_c1") == 1) {
    return "$24,000";
}
End Unverified %]
answered Jul 13 by Zachary Platinum Sawtooth Software, Inc. (63,475 points)
I believe you also need to use the html code for the dollar sign with return text in perl.

[% Begin Unverified Perl
if (GETVALUE("S5_r1_c1") + GETVALUE("S5_r2_c1") == 1) {
    return "&#36;24,000";
}
End Unverified %]
Hi Zachary, I'm getting scripting error when I pasted what you put... Any further thoughts?
 ErrorNum= 132 msg= There is an error in SSI Web Scripting: Script:if (GETVALUE("S5_r1_c1") + GETVALUE("S5_r2_c1") == 1) {
    return "$24,000";
} | Server Error: Undefined subroutine &authlib7_0_30::GETVALUE called at (eval 25) line 1, <GEN1> line 12.
Thanks.
It sounds like GETVALUE was introduced in SSI Web 8.  Try replacing both of those with "VALUE".
Yes, that was it, thanks so much... however I need to add one more scenario to the logic.  Can you help by chance... if keeps giving me an error.
The S6 is what I added in.

[% Begin Unverified Perl
if (VALUE("S5_r1_c1") + VALUE("S5_r2_c1") + VALUE("S5_r3_c1") == 1 & VALUE("S6") == 2"))) {
    return "\$24,000";
}
End Unverified %]
You have three close parens where only one should be, you need two ampersands instead of one, and there's a quotation mark that shouldn't be there:

if (VALUE("S5_r1_c1") + VALUE("S5_r2_c1") + VALUE("S5_r3_c1") == 1 && VALUE("S6") == 2) {
    return "\$24,000";
}
Thanks so much! I appreciate your time and assistance.
Hi Zachary,

I have another Unverified perl question, would you be able to help me again? You helped me out greatly last time...
...