Have an idea?

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

ListLabel Error in for loop

the below code is working fine

strErrorMessage = "You can't Select " + [%ListLabel(QM6ColList, 1)%] + " in both columns";


however below is not

strErrorMessage = "You can't Select " + [%ListLabel(QM6ColList, i)%] + " in both columns";


Please help
related to an answer for: Need to get Label value
asked Aug 21, 2013 by Abdul Bronze (2,630 points)
What is "i" in the script?
This is my complete code


var i=0;
for(i=1;i<5;i++)
{

    if(SSI_GetValue("QM6_r" + i + "_c1")==1 && SSI_GetValue("QM6_r" + i + "_c2")==1)
    {
        strErrorMessage = "You can't Select " + [%ListLabel(QM6ColList, i)%] + " in both columns";
    }

}

1 Answer

+1 vote
The variable "i" will not work inside of your inline SSI-script because the SSI-script is computed before the JavaScript.

I would create a JavaScript variable (array) to hold all the Labels.
var QM6ColList = [% ListLabelsArray(QM6ColList) %];

Since your rows start at 1 and the array will start at position 0, we will have to adjust the index by -1.
strErrorMessage = "You can't Select " + QM6ColList[i-1] + " in both columns";


Additionally, you may want to move the declaration of "i" into your for-parameters (for good practice, not required).
for(var i=1;i<5;i++)


Complete code:
var QM6ColList = [% ListLabelsArray(QM6ColList) %];

for(var i=1;i<5;i++)
{
 
    if(SSI_GetValue("QM6_r" + i + "_c1")==1 && SSI_GetValue("QM6_r" + i + "_c2")==1)
    {
        
        strErrorMessage = "You can't Select " + QM6ColList[i-1] + " in both columns";
    }
 
}
answered Aug 29, 2013 by Ola Blissing Bronze (1,050 points)
edited Aug 29, 2013 by Ola Blissing
It works great. Thank you so much.
...