dleahy Posted June 13, 2012 Share Posted June 13, 2012 Have three pages in my PDF (Body 1, Body 2, Body 3) Trying to get them to displayed based on values entered in a field called "SelectStyle" Basically what I want to accomplish is this: IF Field SelectStyle = "FJ Icon (M)" then display Body 2 IF Field SelectStyle = "DryJoys Tour (M)" then display Body 3 ELSE display Body 1 Here is what I got that's not working: if (GetFileName(Field("SelectStyle")) == "FJ Icon (M)") { FusionPro.Composition.SetBodyPageUsage("Body2", true); FusionPro.Composition.SetBodyPageUsage("Body1", false); FusionPro.Composition.SetBodyPageUsage("Body3", false) { if (GetFileName(Field("SelectStyle")) == "DryJoys Tour (M)") { FusionPro.Composition.SetBodyPageUsage("Body3", true); FusionPro.Composition.SetBodyPageUsage("Body2", false); FusionPro.Composition.SetBodyPageUsage("Body1", false) } else FusionPro.Composition.SetBodyPageUsage("Body1", true); FusionPro.Composition.SetBodyPageUsage("Body2",false); FusionPro.Composition.SetBodyPageUsage("Body3",false) }} Can anyone see what I'm doing wrong?!? Thanks ahead of time! Quote Link to comment Share on other sites More sharing options...
esmith Posted June 13, 2012 Share Posted June 13, 2012 anyone see what I'm doing wrong?!? I edited your code with a few minor adjustments. My changes are in red: if (Field("SelectStyle") == "FJ Icon (M)") { FusionPro.Composition.SetBodyPageUsage("Body2", true); FusionPro.Composition.SetBodyPageUsage("Body1", false); FusionPro.Composition.SetBodyPageUsage("Body3", false) [color=red]} else[/color] if (Field("SelectStyle") == "DryJoys Tour (M)") { FusionPro.Composition.SetBodyPageUsage("Body3", true); FusionPro.Composition.SetBodyPageUsage("Body2", false); FusionPro.Composition.SetBodyPageUsage("Body1", false) } else [color=red]{[/color] FusionPro.Composition.SetBodyPageUsage("Body1", true); FusionPro.Composition.SetBodyPageUsage("Body2",false); FusionPro.Composition.SetBodyPageUsage("Body3",false) } I also removed the GetFileName() code and some unnecessary brackets. There are other ways to set this logic up that simplify the rule, but your logic is not incorrect. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted June 13, 2012 Share Posted June 13, 2012 Set all three body pages to Unused in the Page Usage dialog, then the rule can simply do this: switch (Field("SelectStyle")) { case "FJ Icon (M)": FusionPro.Composition.SetBodyPageUsage("Body2", true); break; case "DryJoys Tour (M)": FusionPro.Composition.SetBodyPageUsage("Body3", true); break; default: FusionPro.Composition.SetBodyPageUsage("Body1", true); } Quote Link to comment Share on other sites More sharing options...
dleahy Posted June 13, 2012 Author Share Posted June 13, 2012 Big thanks to both of you on responding so quickly! I actually found an example of the switch rule and applied it similar to what Dan just laid out... Quote Link to comment Share on other sites More sharing options...
dleahy Posted June 14, 2012 Author Share Posted June 14, 2012 (edited) All, I'm using the switch rule, like Dan mentioned above, on a new template I'm constructing. I need to be able to nest a else if statement in the switch rule yet I don't know quite how to do it. I have to take the code above: switch (Field("SelectStyle")) { case "FJ Icon (M)": FusionPro.Composition.SetBodyPageUsage("Body2", true); break; case "DryJoys Tour (M)": FusionPro.Composition.SetBodyPageUsage("Body3", true); break; default: FusionPro.Composition.SetBodyPageUsage("Body1", true); }and be able to say something like this logic: switch (Field("SelectStyle")) { case "FJ Icon (M)": FusionPro.Composition.SetBodyPageUsage("Body2", true); else if Field("MemberGuestNameofEvent") == "" return FusionPro.Composition.SetBodyPageUsage("Body4", true); break; case "DryJoys Tour (M)": FusionPro.Composition.SetBodyPageUsage("Body3", true); break; default: FusionPro.Composition.SetBodyPageUsage("Body1", true); }So basically I need to be able to say if SelectStyle = "FJ Icon (M)" then return "Body2" unless MemberGuestNameofEvent = "" then return "Body4" Any help with that would be most appreciated! -Dan Edited June 14, 2012 by dleahy Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted June 14, 2012 Share Posted June 14, 2012 So basically I need to be able to say if SelectStyle = "FJ Icon (M)" then return "Body2" unless MemberGuestNameofEvent = "" then return "Body4" It's just a matter of getting the nesting right. This should work: switch (Field("SelectStyle")) { case "FJ Icon (M)": if (Field("MemberGuestNameofEvent") == "") FusionPro.Composition.SetBodyPageUsage("Body4", true); else FusionPro.Composition.SetBodyPageUsage("Body2", true); break; case "DryJoys Tour (M)": FusionPro.Composition.SetBodyPageUsage("Body3", true); break; default: FusionPro.Composition.SetBodyPageUsage("Body1", true); }This is equivalent, but a bit more succinct: switch (Field("SelectStyle")) { case "FJ Icon (M)": FusionPro.Composition.SetBodyPageUsage(Field("MemberGuestNameofEvent") ? "Body2" : "Body4", true); break; case "DryJoys Tour (M)": FusionPro.Composition.SetBodyPageUsage("Body3", true); break; default: FusionPro.Composition.SetBodyPageUsage("Body1", true); }And this would be pretty much the ultimate reduction of the logic: function PageToActivate() { switch (Field("SelectStyle")) { case "FJ Icon (M)": return Field("MemberGuestNameofEvent") ? "Body2" : "Body4"; case "DryJoys Tour (M)": return "Body3"; default: return "Body1"; } } FusionPro.Composition.SetBodyPageUsage(PageToActivate(), true);I like to abstract things out as much as possible and avoid repeating similar bits of code, but that's my geeky perfectionist programmer coming out. Quote Link to comment Share on other sites More sharing options...
dleahy Posted June 14, 2012 Author Share Posted June 14, 2012 I've never met a programmer who used the word succinct before. You must of minored in English... Quote Link to comment Share on other sites More sharing options...
dleahy Posted July 24, 2012 Author Share Posted July 24, 2012 Dan, What if you have multiple fields to verify. This logic doesn't seem to work: if (Field("SelectTopicCATone") != "") { FusionPro.Composition.SetBodyPageUsage("Body1", true); } else if (Field("SelectTopicCATtwo") != "") { FusionPro.Composition.SetBodyPageUsage("Body2", true) && FusionPro.Composition.SetBodyPageUsage("Body1", false); } else if (Field("SelectTopicCATthree") != "") { FusionPro.Composition.SetBodyPageUsage("Body3", true) && FusionPro.Composition.SetBodyPageUsage("Body2", false) && FusionPro.Composition.SetBodyPageUsage("Body1", false); } Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 25, 2012 Share Posted July 25, 2012 What if you have multiple fields to verify. This logic doesn't seem to work: if (Field("SelectTopicCATone") != "") { FusionPro.Composition.SetBodyPageUsage("Body1", true); } else if (Field("SelectTopicCATtwo") != "") { FusionPro.Composition.SetBodyPageUsage("Body2", true) && FusionPro.Composition.SetBodyPageUsage("Body1", false); } else if (Field("SelectTopicCATthree") != "") { FusionPro.Composition.SetBodyPageUsage("Body3", true) && FusionPro.Composition.SetBodyPageUsage("Body2", false) && FusionPro.Composition.SetBodyPageUsage("Body1", false); } Don't use a logical AND operator (&&) in between two statements. This should work: if (Field("SelectTopicCATone") != "") { FusionPro.Composition.SetBodyPageUsage("Body1", true); } else if (Field("SelectTopicCATtwo") != "") { FusionPro.Composition.SetBodyPageUsage("Body2", true); FusionPro.Composition.SetBodyPageUsage("Body1", false); } else if (Field("SelectTopicCATthree") != "") { FusionPro.Composition.SetBodyPageUsage("Body3", true); FusionPro.Composition.SetBodyPageUsage("Body2", false); FusionPro.Composition.SetBodyPageUsage("Body1", false); }Again, though, if you set all three pages to be Unused initially, the rule becomes much simpler: if (Field("SelectTopicCATone") != "") FusionPro.Composition.SetBodyPageUsage("Body1", true); else if (Field("SelectTopicCATtwo") != "") FusionPro.Composition.SetBodyPageUsage("Body2", true); else if (Field("SelectTopicCATthree") != "") FusionPro.Composition.SetBodyPageUsage("Body3", true);Or, even better: FusionPro.Composition.SetBodyPageUsage("Body1", Field("SelectTopicCATone") != ""); FusionPro.Composition.SetBodyPageUsage("Body2", Field("SelectTopicCATtwo") != ""); FusionPro.Composition.SetBodyPageUsage("Body3", Field("SelectTopicCATthree") != ""); Quote Link to comment Share on other sites More sharing options...
dleahy Posted July 25, 2012 Author Share Posted July 25, 2012 This isn't working. Keeps giving me only the first page. I wonder if it is the "else ifs"... Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 25, 2012 Share Posted July 25, 2012 This isn't working. Keeps giving me only the first page. I wonder if it is the "else ifs"... Ah, my last example might not work. The others should be equivalent, though. At any rate, you didn't specify what the right logic should be. It seemed from your original code example that you want to activate just one page in each case. Is that not true? What exactly do you want to happen? Quote Link to comment Share on other sites More sharing options...
dleahy Posted July 25, 2012 Author Share Posted July 25, 2012 Yes. In Marcom Central a user has the ability to select a bunch of different values in 3 unique dropdowns. If they select a value in just the first dropdown and leave the next two blank then it should use the page "Body1" as the template. If they select a value in the first and second dropdowns but not the third, then it should use the page "Body2" as the template. If they select a value in all three dropdowns then it should use the page "Body3" as the template. Make sense? Logically it seems my code should work but it isn't. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 25, 2012 Share Posted July 25, 2012 Yes. In Marcom Central a user has the ability to select a bunch of different values in 3 unique dropdowns. If they select a value in just the first dropdown and leave the next two blank then it should use the page "Body1" as the template. If they select a value in the first and second dropdowns but not the third, then it should use the page "Body2" as the template. If they select a value in all three dropdowns then it should use the page "Body3" as the template. Make sense? Logically it seems my code should work but it isn't. I see. So what happens if they select just the third but not the first two? Or does the MarcomCentral UI not allow that? In any case, I think what you want is this: if (Field("SelectTopicCATthree")) FusionPro.Composition.SetBodyPageUsage("Body3", true); else if (Field("SelectTopicCATtwo")) FusionPro.Composition.SetBodyPageUsage("Body2", true); else FusionPro.Composition.SetBodyPageUsage("Body1", true);Make sure you set all pages to Unused initially in the Page Usage dialog. Quote Link to comment Share on other sites More sharing options...
dleahy Posted July 25, 2012 Author Share Posted July 25, 2012 Ya that worked perfect! Thanks! Never thought of writing the code that way. Yes, usually I use UI rules to prevent them from selecting just the third but not the first two... 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.