Have an idea?

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

Is it possible to add together two values that come from a loop questions


I created a numeric question that is looping the items selected in a previous question.  

I would like to take the answers from the loop and add the values together.  For example  item.1 + item.2 etc.   then create a constructed list using Perl.

I used the below code but it is not working.

my $val_1 = GETVALUE("QS4b.1") + GETVALUE("QS4b.2") + GETVALUE("QS4b.3") ;

my $val_2 = GETVALUE ("QS4b.7") + GETVALUE ("QS4b.11") ;

if  ($val_1  > $val_2)
     ADD ("Item",1);

Thank you in advance for any help that can be provided.
asked Jan 16, 2019 by anonymous
Nothing about the code excerpt above stands out to me as obviously problematic.  Can you expound on what exactly is not working?  Does your survey hit an error when this code is ran, or perhaps the constructed list is just always empty?

Beyond that, I would just double check that your numeric question is named "QS4b" and your list's parent list is named "Item," with that exact casing.
Hi Zachary,

The constructed list is always empty
Curious.  And the names are correct?

Would it be possible to send a copy of your .ssi to support@sawtoothsoftware.com so I might more easily look into what is happening?  Of course, any sensitive or irrelevant information can be removed from the questionnaire before sending it.
Hi Zachary,

I figured out the error in my code.    

For greater than or equal, I was using => instead of >=

Thank you for looking over my code and I apologize for the time you took for such a minor error :)
First thing that stands out is that the symbol for greater-than-or-equal-to is ">=" not "=>".

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.