Have an idea?

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

Weird thing happening with perl in a grid

Hello! So I am using the following Perl to pull in the rows selected in column one of another grid into the rows of a new grid. For some reason though, no matter how many rows qualify it won't pull in more than 4  into the new grid. Has anyone seen this before/ maybe know if it has something to do with my Perl or the grid settings? Thanks

Begin Unverified Perl
if(GETVALUE("S6_r4_c1")==1){
ADD("S6RowList",4)
}
if(GETVALUE("S6_r5_c1")==1){
ADD("S6RowList",5)
}
if(GETVALUE("S6_r6_c1")==1){
ADD("S6RowList",6)
}
if(GETVALUE("S6_r7_c1")==1){
ADD("S6RowList",7)
}
if(GETVALUE("S6_r8_c1")==1){
ADD("S6RowList",8)
}
if(GETVALUE("S6_r9_c1")==1){
ADD("S6RowList",9)
}
if(GETVALUE("S6_r10_c1")==1){
ADD("S6RowList",10)
}
if(GETVALUE("S6_r11_c1")==1){
ADD("S6RowList",11)
}
if(GETVALUE("S6_r12_c1")==1){
ADD("S6RowList",12)
}
if(GETVALUE("S6_r14_c1")==1){ADD("S6RowList",14)
}
if(GETVALUE("S6_r15_c1")==1){ADD("S6RowList",15)
}
if(GETVALUE("S6_r16_c1")==1){ADD("S6RowList",16)
}

End Unverified
asked Sep 25, 2018 by kristy (160 points)

1 Answer

+1 vote
Here's some issues to start with ...

Should you be adding a ";" after each ADD command?

e.g. ADD("S6RowList",4);

Also, ensure your variable names from S6 are correct. Make sure they actually exist.

Have you also defined all the necessary codes 1-16 in your parent list S6RowList?

To lighten the load on your script, you could use a for loop (see below) ...
Begin Unverified Perl

 my $i=4;

 for($i=4; $i<=16; $i++)
  {
   if (VALUE("S6_r".$i."_c1")==1)
    {  
     ADD("S6RowList",$i);
    }  
  }

 REMOVE("S6RowList",13);

End Unverified

Let me know how you go.
answered Sep 25, 2018 by Paul Moon Platinum (74,405 points)
edited Sep 25, 2018 by Paul Moon
The loop worked, thank you!
You beauty!

Try to get your code working too. Go through that list of issues I mentioned.
...