Have an idea?

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

How to call mother brand in a dynamic list if its any of sub-brands has been selected in a parent list?

I need to call mother brand in a constructed list if its any of sub-brands has been selected in a parent list?

Such as the mother brand is Telenore and the sub brands are Talkshawk and Talkshawk60

If either of both Talkshawk and Talkshwk60 selected in the parent list I need to display only Telenor in the constructed list instead of the sub brands. How it is possible in the earlier sawtooth versions?

Furthermore, I have to call the mother brands from multiple questions such as Top of Mind list (single response), Spont and aided awareness and need to display the mother brands in the later question.

Currently I am using AIC but it displays all the selected brands whereas I have to display only the mother brands even if they are not selected and their sub brands are selected.
asked Aug 26, 2014 by Rashid (230 points)

1 Answer

0 votes
You need to create seperate pre defined list with mother brand. Let say your list name is ''mainBrandList" with options

1. Brand1
2. Brand2
3. Brand3

Now let's say you have Q1 where you are asking sub-brand of these mother brand. Those options are


Now to call mother brand to another question you should create separate constructed list and use perl code to add mother brand here.  Let say my constructed list name is "MotherBrand", parent list shoud be "mainBrandList" for this constructed list.

Begin Unverified Perl
if(VALUE('Q1_1')==1 or VALUE('Q1_2')==1)
if(VALUE('Q1_3')==1 or VALUE('Q1_4')==1)
if(VALUE('Q1_5')==1 or VALUE('Q1_6')==1)
End Unverified

You need to call this "MotherBrand" List now where you want to use.

Let me know in case of more clarification.
answered Aug 26, 2014 by Rajesh Rana Gold (24,770 points)
Thanks a lot for your answer.

Can we perform this from more than one single and multiple response lists to compile the mother brands lists? I need to call this from TOM, Spont and Aided awareness questions for long list of brands.
Yes, you need to modify perl code based on those 2 or 3 quesiton, add all condition there. Let's say Q1 is multiselect and Q2 is single select, then code would be

if(VALUE('Q1_1')==1 or Value('Q1_2')==1 or VALUE('Q2')==1 or VALUE('Q2')==2)
Thanks a lot again.

I have made predefined MotherBrandList containing 7 main brands. The main brands list is MBL

Have added the given below script in a constructed list

Begin Unverified Perl
if(VALUE('M1_1')==1 or VALUE('M1_7')==1) or VALUE('M1_8')==1) or VALUE('M2_r1_c1_1')==1) or VALUE('M2_r7_c1_1')==1) or VALUE('M2_r8_c1_1')==1) or VALUE('M3_r1_c1_1')==1) or VALUE('M3_r7_c1_1')==1) or VALUE('M3_r8_c1_1')==1)
if(VALUE('M1_10')==1 or VALUE('M1_12')==1) or VALUE('M1_13')==1) or VALUE('M2_r10_c1_1')==1) or VALUE('M2_r12_c1_1')==1) or VALUE('M2_r13_c1_1')==1) or VALUE('M3_r10_c1_1')==1) or VALUE('M3_r12_c1_1')==1) or VALUE('M3_r13_c1_1')==1)
if(VALUE('M1_15')==1 or VALUE('M1_20')==1) or VALUE('M1_21')==1) or VALUE('M2_r15_c1_1')==1) or VALUE('M2_r20_c1_1')==1) or VALUE('M2_r21_c1_1')==1) or VALUE('M3_r15_c1_1')==1) or VALUE('M3_r20_c1_1')==1) or VALUE('M3_r21_c1_1')==1)
if(VALUE('M1_23')==1 or VALUE('M1_28')==1) or VALUE('M1_29')==1) or VALUE('M2_r23_c1_1')==1) or VALUE('M2_r28_c1_1')==1) or VALUE('M2_r29_c1_1')==1) or VALUE('M3_r23_c1_1')==1) or VALUE('M3_r28_c1_1')==1) or VALUE('M3_r29_c1_1')==1)
if(VALUE('M1_31')==1 or VALUE('M1_32')==1) or VALUE('M2_r31_c1_1')==1) or VALUE('M2_r32_c1_1')==1) or VALUE('M3_r31_c1_1')==1) or VALUE('M3_r32_c1_1')==1)
if(VALUE('M1_35')==1 or VALUE('M1_36')==1) or VALUE('M1_37')==1) or VALUE('M2_r35_c1_1')==1) or VALUE('M2_r36_c1_1')==1) or VALUE('M2_r37_c1_1')==1) or VALUE('M3_r35_c1_1')==1) or VALUE('M3_r36_c1_1')==1) or VALUE('M3_r37_c1_1')==1)
if(VALUE('M1_43')==1 or VALUE('M1_44')==1) or VALUE('M1_45')==1) or VALUE('M2_r43_c1_1')==1) or VALUE('M2_r44_c1_1')==1) or VALUE('M2_r45_c1_1')==1) or VALUE('M3_r43_c1_1')==1) or VALUE('M3_r44_c1_1')==1) or VALUE('M3_r45_c1_1')==1)
End Unverified

Am getting the given below error while survey reaching the question where I have called this constructed list:

Error #117
Script error.

Check the error log for details.

Can you please further help in this regard?
Just some friendly advice when tackling long and lengthy Perl script. When it gets long and looks nasty, try to just write one of the conditions and get it working first. That way your syntax will only be incorrect in one spot rather than many spots within your programming script.

I can see some syntax errors in the above code which I'll gladly point out.
if(VALUE("M1_1")==1 || VALUE("M1_7")==1) || VALUE("M1_8")==1) || VALUE("M2_r1_c1_1")==1) || VALUE("M2_r7_c1_1")==1) || VALUE("M2_r8_c1_1")==1) || VALUE("M3_r1_c1_1")==1) || VALUE("M3_r7_c1_1")==1) || VALUE("M3_r8_c1_1")==1)

Note the following ...

1/ Perl is case sensitive so your variable names must be written exactly as you defined them. I assume you have followed this rule.
2/ Also check the Sawtooth help on list functions as the functions are also case sensitive for Perl. You will see they are written differently when used in SSI Script.
3/ All of your "or" commands need to be replaced by "||". Again, check the Sawtooth help for examples of Perl programming. That will certainly assist.
4/ All of you variables need the single quotes replaced by the double quotes. See my code where the VALUE and ADD commands have been used.

I encourage you to jump on the forum and seek assistance as there is plenty of talented people willing to help.
I almost forgot to mention the nesting of your brackets needs attention too. You did have some missing brackets that would have prevented the code from being executed successfully.
if((VALUE("M1_1")==1) || (VALUE("M1_7")==1) || (VALUE("M1_8")==1) || (VALUE("M2_r1_c1_1")==1) || (VALUE("M2_r7_c1_1")==1) || (VALUE("M2_r8_c1_1")==1) || (VALUE("M3_r1_c1_1")==1) || (VALUE("M3_r7_c1_1")==1) || (VALUE("M3_r8_c1_1")==1))
Thank you very much Paul. I have tried my best but there is no luck. Have attempted many combinations. Using single column single response grid based question, given below seems me the most right script:

Begin Unverified Perl
if((VALUE("M1_c1_1")==1) || (VALUE("M1_c1_7")==1) || (VALUE("M1_c1_8")==1))
End Unverified

Referring to MBL parent list in the construction list that contains sub brands. Now there are no errors but the page is not displayed and every time skips automatically. Have deleted all skipping and other questions from the questionnaire to avoid any complexity and to diagnose it.

Is this possible if someone can help me. I am really stuck on this and have been in too much pressure.

Thank you very much.
Now that the syntax errors have gone it tells me that your constructed list must be empty. If the constructed list is empty, Sawtooth will automatically skip the page.

I'm looking at your variable names, they appear to be incorrectly named in you IF statement? If these are check box variables within your grid, shouldn't they be in the format GridName_r#_c#, so M1_r8_c1 would be a good example?

Try checking and correcting your variable names. I suspect this is your problem. If you still have problems, send me your ssi file and I will take a look.

Send to paul.moon@beatonglobal.com. I'm based in Australia so you may want to note the time difference.
Thank you very much Paul. The program is working now. I was actually calling constructed list in first question (M1) as has I have to remove few brands from the major list for the first question as well. However, providing predefined master brand list (MBL) the problem of the program has resolved.

My another question is if there is  any way to remove showing few brands in the predefined list in a question?  Or there is any other good logic to control this?
Great news. Good to see you got it working. And it's examples like this that help with your skills no doubt. You will be so much better next time when a problem like this arises.

With list building, you need to add the codes before you remove them.

Use list functions like ADD, AIC, ANC, AIE, etc. to add to your constructed list. You can use functions like this to only add the codes you desire.

To remove codes from your list, you can use list functions RIC, Remove, etc.

Best you look these functions up in the Sawtooth help for a better explanation. And you should practice and do some testing.
I am happy for Rashid, he could get help from forum.

Amazing Paul.
When I am trying to call single brand the code is working but when I am trying to call 2 or more brands it shows irrelevant brands.  Can you please check the given below code if I am missing something such as any bracket?

Begin Unverified Perl
if((VALUE("M1_c1")==1) || (VALUE("M1_c1")==7) || (VALUE("M1_c1")==8) || (VALUE("M2_r1_c1")==1) || (VALUE("M2_r7_c1")==1) || (VALUE("M2_r8_c1")==1) || (VALUE("M3_r1_c1")==1) || (VALUE("M3_r7_c1")==1) || (VALUE("M3_r8_c1")==1))
if((VALUE("M1_c1")==10) || (VALUE("M1_c1")==12) || (VALUE("M1_c1")==13) || (VALUE("M2_r10_c1")==1) || (VALUE("M2_r12_c1")==1) || (VALUE("M2_r13_c1")==1) || (VALUE("M3_r10_c1")==1) || (VALUE("M3_r12_c1")==1) || (VALUE("M3_r13_c1")==1))
end unverified

Thank you very much Paul and Rajesh for your wonderful help on this forum.
Firstly, I would correct your "end unverified" to "End Unverified". Not sure the affect this has but it may pose a problem?

I can't see any other obvious syntax errors in the script you provided. That looks good.

Double check you variable names. They must be spelt exactly as you defined them as Perl is case sensitive.

I'm not sure what you mean by ...

"When I am trying to call single brand the code is working but when I am trying to call 2 or more brands it shows irrelevant brands."

I would need a further explanation on "irrelevant brands".