seymoujd Posted May 5, 2015 Share Posted May 5, 2015 I need some help with this. Im trying to write a rule that hides pages based on a selection from a drop down menu. The rule validates as "Expressions OK" but when I go to preview it doesn't work. I am able to get it to work if i write it out the long way with out the for loop I was just hoping to avoid the extra typing. var pages = ["Cert 1","Cert 2","Cert 3","Cert 4","Cert 5"] if(Field("Choose A Certificate")=="NSU Certificates.jpg") {for (i=1; i<pages.length; i++); {FusionPro.Composition.SetBodyPageUsage(, false)} }; Quote Link to comment Share on other sites More sharing options...
GreggRusson Posted May 5, 2015 Share Posted May 5, 2015 I'm assuming here that you've named your body pages 'Cert n'. But the SetBodyPage method needs the name of the page you want to turn off or on. FusionPro.Composition.SetBodyPageUsage(pages, false); Gregg Quote Link to comment Share on other sites More sharing options...
step Posted May 5, 2015 Share Posted May 5, 2015 You need to reference the name of the array ("pages") when you want to call out a value by its position which I'm assuming you're trying to do in "SetBodyPageUsage." So, that line should be changed to this: {FusionPro.Composition.SetBodyPageUsage(pages[i], false)} I'm not sure if it's intentional or not, but you're only turning off 4 pages (Cert 2 - 5) since you're setting 'i' equal to 1 rather than 0. If you want to turn off all pages in the array you need to modify the code to this: var pages = ["Cert 1","Cert 2","Cert 3","Cert 4","Cert 5"]; if(Field("Choose A Certificate")=="NSU Certificates.jpg"){ for (var i=0; i<pages.length; i++){ FusionPro.Composition.SetBodyPageUsage(pages[i], false); } } You could also do it without the array at all: if(Field("Choose A Certificate")=="NSU Certificates.jpg"){ for (var i=1; i<=5; i++){ FusionPro.Composition.SetBodyPageUsage("Cert " + i, false); } } Quote Link to comment Share on other sites More sharing options...
seymoujd Posted May 5, 2015 Author Share Posted May 5, 2015 Thank you. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 5, 2015 Share Posted May 5, 2015 You need to reference the name of the array ("pages") when you want to call out a value by its position which I'm assuming you're trying to do in "SetBodyPageUsage." So, that line should be changed to this: {FusionPro.Composition.SetBodyPageUsage(pages[i], false)} True, although, in the original post, you would also need to remove the semicolon from the end of this line: {for (i=1; i<pages.length; i++); Otherwise, the loop isn't going to do anything at all. I'm not sure if it's intentional or not, but you're only turning off 4 pages (Cert 2 - 5) since you're setting 'i' equal to 1 rather than 0. If you want to turn off all pages in the array you need to modify the code to this: var pages = ["Cert 1","Cert 2","Cert 3","Cert 4","Cert 5"]; if(Field("Choose A Certificate")=="NSU Certificates.jpg"){ for (var i=0; i<pages.length; i++){ FusionPro.Composition.SetBodyPageUsage(pages[i], false); } } Right, array indices in JavaScript start at zero, not one. Although, instead of initializing a numeric index, and trying to specify the upper and lower bounds correctly (which is easy to get wrong), it's more reliable to use the for...in syntax instead: for (var i in pages) FusionPro.Composition.SetBodyPageUsage(pages[i], false); You could also do it without the array at all: if(Field("Choose A Certificate")=="NSU Certificates.jpg"){ for (var i=1; i<=5; i++){ FusionPro.Composition.SetBodyPageUsage("Cert " + i, false); } } True, but if these are the first five pages of the template, you can also do it purely by page number: if (Field("Choose A Certificate") == "NSU Certificates.jpg") { for (var i=1; i<=5; i++) FusionPro.Composition.SetBodyPageUsage(i, false); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.