Jump to content

Multiple Versions using Body Pages


wenstjohn

Recommended Posts

I have a job that uses 7 page versions (16 body pages include a blank option; fronts and backs) based on a field in the data ("ArtName"). I have written a OnRecordStart rule that verifies ok but when the file is output, on the first 6 records, it sees the blank page which is the "else" statement. Only one of the body pages "NearlyGoldABClub_front and back" work correctly. Can you take a look at my rule and see if I am making a mistake somewhere or if I should be doing this a different way.

Thanks!! PS. I had to attach the rule as a text file because it was too long.

Edited by wenstjohn
Link to comment
Share on other sites

Thanks. Regarding getting code to show up, if you click the "Go Advanced" button, right below the area where you type, then you will have more options, including a button that looks like # (like a pound or "hash tag" sign), which creates a CODE block.

 

As for your rule, it can definitely be simplified quite a bit. The first thing I would do would be to set all of the pages to be Unused initially; then you can get rid all the lines of code which call FusionPro.Composition.SetBodyPageUsage with the second parameter "false." That will reduce the code to this:

if (Field("ArtName") == "annivGOLD")
{
   FusionPro.Composition.SetBodyPageUsage("AnnivGold_front", true);
   FusionPro.Composition.SetBodyPageUsage("AnnivGold_back", true);
}
if (Field("ArtName") == "annivPLTN")
{
   FusionPro.Composition.SetBodyPageUsage("AnnivPlat_front", true);
   FusionPro.Composition.SetBodyPageUsage("AnnivPlat_back", true);
}
if (Field("ArtName") == "high_valueCLUB")
{
   FusionPro.Composition.SetBodyPageUsage("HighValueClub_front", true);
   FusionPro.Composition.SetBodyPageUsage("HighValueClub_back", true);
}
if (Field("ArtName") == "inact_platPLTN")
{
   FusionPro.Composition.SetBodyPageUsage("InactivePltn_front", true);
   FusionPro.Composition.SetBodyPageUsage("InactivePltn_back", true);
}
if (Field("ArtName") == "nearly eliteCLUB")
{
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_front", true);
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_back", true);
}
if (Field("ArtName") == "nearly eliteGOLD")
{
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteGold_back", true);
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_front", true);
}
if (Field("ArtName") == "nearly gold A/BCLUB")
{
   FusionPro.Composition.SetBodyPageUsage("NearlyGoldABClub_front", true);
   FusionPro.Composition.SetBodyPageUsage("NearlyGoldABClub_back", true);
}
else
{
   FusionPro.Composition.SetBodyPageUsage("Blank_front", true);
   FusionPro.Composition.SetBodyPageUsage("Blank_back", true);
}

Now we can see what the problem is. Regardless of whatever else happens in the rule, it gets to this line:

if (Field("ArtName") == "nearly gold A/BCLUB")

And if that condition is not met, it always goes into that final "else" block.

 

The way to fix this is to convert all those "if" statements need to be "else if", like so:

if (Field("ArtName") == "annivGOLD")
{
   FusionPro.Composition.SetBodyPageUsage("AnnivGold_front", true);
   FusionPro.Composition.SetBodyPageUsage("AnnivGold_back", true);
}
else if (Field("ArtName") == "annivPLTN")
{
   FusionPro.Composition.SetBodyPageUsage("AnnivPlat_front", true);
   FusionPro.Composition.SetBodyPageUsage("AnnivPlat_back", true);
}
else if (Field("ArtName") == "high_valueCLUB")
{
   FusionPro.Composition.SetBodyPageUsage("HighValueClub_front", true);
   FusionPro.Composition.SetBodyPageUsage("HighValueClub_back", true);
}
else if (Field("ArtName") == "inact_platPLTN")
{
   FusionPro.Composition.SetBodyPageUsage("InactivePltn_front", true);
   FusionPro.Composition.SetBodyPageUsage("InactivePltn_back", true);
}
else if (Field("ArtName") == "nearly eliteCLUB")
{
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_front", true);
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_back", true);
}
else if (Field("ArtName") == "nearly eliteGOLD")
{
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteGold_back", true);
   FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_front", true);
}
else if (Field("ArtName") == "nearly gold A/BCLUB")
{
   FusionPro.Composition.SetBodyPageUsage("NearlyGoldABClub_front", true);
   FusionPro.Composition.SetBodyPageUsage("NearlyGoldABClub_back", true);
}
else
{
   FusionPro.Composition.SetBodyPageUsage("Blank_front", true);
   FusionPro.Composition.SetBodyPageUsage("Blank_back", true);
}

Although, there's a much simpler syntax for this kind of chained "else if" logic, which is doing comparisons to the same variable: you can use a switch statement instead, like so:

switch (Field("ArtName"))
{
   case "annivGOLD":
       FusionPro.Composition.SetBodyPageUsage("AnnivGold_front", true);
       FusionPro.Composition.SetBodyPageUsage("AnnivGold_back", true);
       break;

   case "annivPLTN":
       FusionPro.Composition.SetBodyPageUsage("AnnivPlat_front", true);
       FusionPro.Composition.SetBodyPageUsage("AnnivPlat_back", true);
       break;

   case "high_valueCLUB":
       FusionPro.Composition.SetBodyPageUsage("HighValueClub_front", true);
       FusionPro.Composition.SetBodyPageUsage("HighValueClub_back", true);
       break;

   case "inact_platPLTN":
       FusionPro.Composition.SetBodyPageUsage("InactivePltn_front", true);
       FusionPro.Composition.SetBodyPageUsage("InactivePltn_back", true);
       break;

   case "nearly eliteCLUB":
       FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_front", true);
       FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_back", true);
       break;

   case "nearly eliteGOLD":
       FusionPro.Composition.SetBodyPageUsage("NearlyEliteGold_back", true);
       FusionPro.Composition.SetBodyPageUsage("NearlyEliteClub_front", true);
       break;

   case "nearly gold A/BCLUB":
       FusionPro.Composition.SetBodyPageUsage("NearlyGoldABClub_front", true);
       FusionPro.Composition.SetBodyPageUsage("NearlyGoldABClub_back", true);
       break;

   default:
       FusionPro.Composition.SetBodyPageUsage("Blank_front", true);
       FusionPro.Composition.SetBodyPageUsage("Blank_back", true);
       break;
}

This could be further reduced in several ways, such as this:

var pagePrefix = "";

switch (Field("ArtName"))
{
   case "annivGOLD":
       pagePrefix = "AnnivGold";
       break;

   case "annivPLTN":
       pagePrefix = "AnnivPlat";
       break;

   case "high_valueCLUB":
       pagePrefix = "HighValueClub";
       break;

   case "inact_platPLTN":
       pagePrefix = "InactivePltn";
       break;

   case "nearly eliteCLUB":
       pagePrefix = "NearlyEliteClub";
       break;

   case "nearly eliteGOLD":
       pagePrefix = "NearlyEliteGold";
       break;

   case "nearly gold A/BCLUB":
       pagePrefix = "NearlyGoldABClub";
       break;

   default:
       pagePrefix = "Blank";
       break;
}

FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_front", true);
FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_back", true);

Or, a bit more succinctly:

function getPagePrefix()
{
   switch (Field("ArtName"))
   {
       case "annivGOLD":
           return "AnnivGold";

       case "annivPLTN":
           return "AnnivPlat";

       case "high_valueCLUB":
           return "HighValueClub";

       case "inact_platPLTN":
           return "InactivePltn";

       case "nearly eliteCLUB":
           return "NearlyEliteClub";

       case "nearly eliteGOLD":
           return "NearlyEliteGold";

       case "nearly gold A/BCLUB":
           return "NearlyGoldABClub";

       default:
           return "Blank";
   }
}

var pagePrefix = getPagePrefix();
FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_front", true);
FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_back", true);

Now we can see that this is really just a simple mapping, which can be accomplished even more succinctly, like so:

var pagePrefixes =
{
   annivGOLD: "AnnivGold",
   annivPLTN: "AnnivPlat",
   high_valueCLUB: "HighValueClub",
   inact_platPLTN: "InactivePltn",
   "nearly eliteCLUB": "NearlyEliteClub",
   "nearly eliteGOLD": "NearlyEliteGold",
   "nearly gold A/BCLUB": "NearlyGoldABClub",
};

var pagePrefix = pagePrefixes[Field("ArtName")] || "Blank";

FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_front", true);
FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_back", true);

Of course, an even simpler solution is to simply name the pages exactly the same as the field values; for instance, name your pages like "high_valueCLUB_front", "high_valueCLUB_back", "nearly eliteCLUB_front", "nearly eliteCLUB_back", etc. Then the rule doesn't need to do any mapping at all; and you just need a bit of error handling for the case where there's no match and you want to use the blank pages, like so:

var pagePrefix = Field("ArtName");
try
{
   FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_front", true);
   FusionPro.Composition.SetBodyPageUsage(pagePrefix + "_back", true);
}
catch (e)
{
   FusionPro.Composition.SetBodyPageUsage("Blank_front", true);
   FusionPro.Composition.SetBodyPageUsage("Blank_back", true);
}

Link to comment
Share on other sites

  • 4 weeks later...

Here's what I use.

 

FusionPro.Composition.SetBodyPageUsage("NSS_F", Field("Shell_F") == "NSSRD_F" || Field("Shell_F") == "NSS_F" || Field("Shell_F") == "NSSFM_F");

FusionPro.Composition.SetBodyPageUsage("NSS_B", Field("Shell_B") == "NSSRD_B" || Field("Shell_B") == "NSS_B" || Field("Shell_B") == "NSSFM_B");

FusionPro.Composition.SetBodyPageUsage("NSSVP_F", Field("Shell_F") == "NSSVP_F");

FusionPro.Composition.SetBodyPageUsage("NSSVP_B", Field("Shell_B") == "NSSVP_B");

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...