Have an idea?

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

Using Perl script within [%%]

I have a survey which has a pass-in field called TYPE.

If TYPE=1, display the logo in the header.
If TYPE=2, do not display the logo in the header.

I was using the following pop-up script as the header when the TYPE condition was not applied ...
[%PopUp("<img src='"&GraphicsPath()&"CompanyLogo.png' alt='' border='0'>","https://www.abcxyz.com.au/",850,650)%]

I then wrote some Perl in the following constructed list (HeaderConList) to select the logo based on the TYPE variable ...
Begin Unverified Perl

 if (VALUE("TYPE")==1)
End Unverified

HeaderList contains 1 code which is defined as the PopUp script mentioned above.

I then used [%ListLabel(HeaderConList,1)%] in the header.

My problem is I have [%%] from the PopUp function inside the Perl script. I know the Perl script works fine as I tested it where the header was simple text.

If I wasn't using the PopUp function and used "img src" only, I wouldn't have this problem.

Looking for a best solution where I can avoid this issue.
asked Mar 27, 2017 by Paul Moon Platinum (101,255 points)
edited Mar 27, 2017 by Paul Moon

1 Answer

+1 vote
If you look at the admin module, you'll notice that the constructed list is always empty.  This suggests that the problem is that your constructed list is being defined on the Start page, before the survey has a saved value for "TYPE."  You can verify that this is the problem by deleting the ListLabel code from the survey header and putting it on the first non-Start page - the code will work.

The simplest solution for this might be to get rid of the lists and just put the unverified Perl straight into the survey header:

[% Begin Unverified Perl
if (VALUE("TYPE") == 1) {
    return POPUP("<img src='" . GRAPHICSPATH() . "CompanyLogo.png' alt='' border='0'>", "https://www.abcxyz.com.au/", 850, 650);
End Unverified %]
answered Mar 27, 2017 by Zachary Platinum Sawtooth Software, Inc. (214,575 points)
Thanks Zachary.

I was well aware the constructed list was empty. If I was simply trying to display text, the Perl worked fine. I got stuck having  "[%%]" inside "[%%]" which you have now helped me to avoid.

Much appreciated as always.