Have an idea?

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

calling last answer in loop

For a few of my questions I am using previously entered information to display in other questions. For example in this case, I am asking if the current loop person lives in one of the places entered in A04B.  This works if A04B was only answered 1 time.  However, it could be that many places are entered in A04B.  I would want to show only the LAST place entered.  Is this possible if I have a loop of unknown iterations (between 1 and 12)?

Does [%LOOPLABEL()%] live in [%Label(A04B.1) %][%Label(A04B.2) %][%Label(A04B.3) %][%Label(A04B.4) %][%Label(A04B.5) %][%Label(A04B.6) %][%Label(A04B.7) %][%Label(A04B.8) %][%Label(A04B.9) %][%Label(A04B.10) %][%Label(A04B.11) %][%Label(A04B.12) %]</td>?</span>
asked Jan 25 by sallen Bronze (2,315 points)

1 Answer

0 votes
We just need to get the last item from the list used in the loop and call Label with that value:

[% Begin Unverified Perl
return LABEL('A04B.' . LISTVALUE('list1', LISTLENGTH('list1')));
End Unverified %]


"list1" should be the name of the loop list.
answered Jan 25 by Zachary Platinum Sawtooth Software, Inc. (206,100 points)
I tried these separately but nothing shows up.  It is strange.
"[% ListLength('household2') %]" displays nothing?  Then the problem isn't with my script - why is text not showing up on your page?
Yes, it shows nothing.  if I type [%Label(A04B.1) %] it shows but not the ListLength or the ListValue one.
Maybe that's something support can look at and walk you through.  I can't say why you wouldn't be seeing anything.
OK. I will reach out to them. thanks.
...