ricky10ss Posted December 5, 2016 Posted December 5, 2016 Below is the onRecordStart rule I was using but I found out I need to adjust to another field. The switch rule below is turning on the specific pages based off their plan. But there is a value field called "Amount" that if there is no value for 250, 500, 750 and 1000 plans they do not get 250_500_750_1000NonInsured P1 or 250_500_750_1000NonInsured P2. What would you recommend doing for this? switch (Field("PLANOPTION")) { case "200": FusionPro.Composition.SetBodyPageUsage("200 P1", true) FusionPro.Composition.SetBodyPageUsage("200 P2", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P2", true) break; case "250": FusionPro.Composition.SetBodyPageUsage("250 P1", true) FusionPro.Composition.SetBodyPageUsage("250 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; case "500": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; case "750": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; case "1000": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; } Quote
Dan Korn Posted December 5, 2016 Posted December 5, 2016 Below is the onRecordStart rule I was using but I found out I need to adjust to another field. The switch rule below is turning on the specific pages based off their plan. But there is a value field called "Amount" that if there is no value for 250, 500, 750 and 1000 plans they do not get 250_500_750_1000NonInsured P1 or 250_500_750_1000NonInsured P2. What would you recommend doing for this? Well, first, the code you provided can be reduced, starting with combining cases that have the same results, in several ways. I'd start with this: switch (Field("PLANOPTION")) { case "200": FusionPro.Composition.SetBodyPageUsage("200 P1", true) FusionPro.Composition.SetBodyPageUsage("200 P2", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P2", true) break; case "250": FusionPro.Composition.SetBodyPageUsage("250 P1", true) FusionPro.Composition.SetBodyPageUsage("250 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; case "500": case "750": case "1000": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; } And then I would further factor out some of the repeated code like so: switch (Field("PLANOPTION")) { case "200": FusionPro.Composition.SetBodyPageUsage("200 P1", true) FusionPro.Composition.SetBodyPageUsage("200 P2", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P2", true) break; case "250": FusionPro.Composition.SetBodyPageUsage("250 P1", true) FusionPro.Composition.SetBodyPageUsage("250 P2", true) break; case "500": case "750": case "1000": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) break; } if (Field("PLANOPTION") != "200") { FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) } Then I think it's pretty obvious how to add the new requirement: switch (Field("PLANOPTION")) { case "200": FusionPro.Composition.SetBodyPageUsage("200 P1", true) FusionPro.Composition.SetBodyPageUsage("200 P2", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P2", true) break; case "250": FusionPro.Composition.SetBodyPageUsage("250 P1", true) FusionPro.Composition.SetBodyPageUsage("250 P2", true) break; case "500": case "750": case "1000": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) break; } if (Field("PLANOPTION") != "200" && Field("Amount")) { FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) } I'm pretty sure that will do what you want. P.S. Further reductions are possible, but the code may be less straightforward. For example: [color="Silver"]var pages = []; switch (Field("PLANOPTION")) { case "200": pages.push("200"); pages.push("200NonInsured"); break; case "250": pages.push("250"); break; case "500": case "750": case "1000": pages.push("500_750_1000"); break; } if (Field("PLANOPTION") != "200" && Field("Amount")) pages.push("250_500_750_1000NonInsured"); for (var p in pages) for (var i = 1; i <= 2; i++) FusionPro.Composition.SetBodyPageUsage(pages[p] + " P" + i, true); [/color] Quote
step Posted December 5, 2016 Posted December 5, 2016 First of all, you're doing exactly the same thing when the value of "PLANOPTION" is "500," "750," or "1000" so you could simplify your code by writing it like this: switch (Field("PLANOPTION")) { case "200": FusionPro.Composition.SetBodyPageUsage("200 P1", true) FusionPro.Composition.SetBodyPageUsage("200 P2", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P2", true) break; case "250": FusionPro.Composition.SetBodyPageUsage("250 P1", true) FusionPro.Composition.SetBodyPageUsage("250 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; case "500": [color="Red"] case "750": case "1000":[/color] FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", true) break; } But there is a value field called "Amount" that if there is no value for 250, 500, 750 and 1000 plans they do not get 250_500_750_1000NonInsured P1 or 250_500_750_1000NonInsured P2. What would you recommend doing for this? In other words, you only want to enable the "250_500_750_1000NonInsured" pages if the "Amount" field contains a value? You can do that: switch (Field("PLANOPTION")) { case "200": FusionPro.Composition.SetBodyPageUsage("200 P1", true) FusionPro.Composition.SetBodyPageUsage("200 P2", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P1", true) FusionPro.Composition.SetBodyPageUsage("200NonInsured P2", true) break; case "250": FusionPro.Composition.SetBodyPageUsage("250 P1", true) FusionPro.Composition.SetBodyPageUsage("250 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", [color="red"]Field("Amount")[/color]) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", [color="red"]Field("Amount")[/color]) break; case "500": case "750": case "1000": FusionPro.Composition.SetBodyPageUsage("500_750_1000 P1", true) FusionPro.Composition.SetBodyPageUsage("500_750_1000 P2", true) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P1", [color="red"]Field("Amount")[/color]) FusionPro.Composition.SetBodyPageUsage("250_500_750_1000NonInsured P2", [color="red"]Field("Amount")[/color]) break; } Or you could not use a switch statement at all: var front = Field("PLANOPTION") > 250 ? '500_750_1000' : ''; var back = Field("PLANOPTION") > 200 ? '250_500_750_1000' : ''; for (var i=1; i<=2; i++) { FusionPro.Composition.SetBodyPageUsage((front || Field("PLANOPTION")) + ' P' + i, true); if (!back || Field("Amount")) FusionPro.Composition.SetBodyPageUsage((back || Field("PLANOPTION")) + 'NonInsured P' + i, true); } Quote
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.