Have an idea?

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

constructed list constant sum questions


I try to construct a list based on the answers of different previous constant sum questions. So for example:

Q1: divide 50 amongst (constant sum)

Q2: divide 50 amongst (constant sum)


constructed list (add items if not equal to 0)
Begin Unverified Perl

if (VALUE("Q1_1") != 0)
    ADD("predefinedlist", 1);
elsif (VALUE("Q1_2") != 0)
    ADD("predefinedlist", 2);
elsif (VALUE("Q2_1") != 0)
    ADD("predefinedlist", 3);
elsif (VALUE("Q2_2")!=0)

    ADD("predefinedlist", 4);
End Unverified

But if i add the constructed list as rows in a grid-questoin, i get an Script error when testing the survey. I probably made a mistake in the script, but i cannot figure out what the mistake is. Could you maybe help me?
asked May 17, 2021 by Jeroen

1 Answer

0 votes
I'm assuming if all conditions were true, you would want all 4 list items to be saved within the constructed list? If that's the case, change all "elsif" statements to "if" statements.

Perl is case sensitive. How have you defined your parent list? Ensure it is scripted exactly as you have defined it, otherwise you will generate an error.

And I assume you have Q1 and Q2 variables defined correctly? Ensure they are also correct and case sensitivity is taken in to account.

And finally, I see you have a missing opening curly bracket on the last condition, so insert the "{".
answered May 17, 2021 by Paul Moon Platinum (101,255 points)
I also noticed what Paul mentioned and would check those things.  Additionally, I would think you could simplify your code with AIG.  So instead of using Perl you could just have this as your constructed list:
Jay, I was thinking the same thing but wasn't certain the parent lists were all the same? If they are the same, then certainly the SSI Script approach you kindly mentioned is the way to go. Thanks mate for chiming in with your usual valuable comments. Thanks buddy.
Yes, of course.  I was making the assumption that they were the same (which could cause confusion if they aren't).  Multiple options!  That's the beauty of this forum is it's all about learning what is possible.  Thanks Paul!
Jeroen now has all options covered with these solutions.