Jump to content

OnRecordStart Switching Pages


slivingston

Recommended Posts

I have 4 versions of a postcard. I have the version in my list to state which version to use. I have all 4 version in one PDF and have named pages 1 and 2 as body and 3-8 as unused. When I compose the file, it uses the default pages of 1 and 2 or the last 2 pages 7 and 8. For the versions that should be using pages 3-6, it is using pages 1 and 2. My script looks as follows:

if (Field("version") == "CORALVILLE")

{

FusionPro.Composition.SetBodyPageUsage("Coralville1", true)

FusionPro.Composition.SetBodyPageUsage("CedarRapids1", false)

FusionPro.Composition.SetBodyPageUsage("Coralville2", true)

FusionPro.Composition.SetBodyPageUsage("CedarRapids2", false)

}

else

{

FusionPro.Composition.SetBodyPageUsage("Coralville1", false)

FusionPro.Composition.SetBodyPageUsage("CedarRapids1", true)

FusionPro.Composition.SetBodyPageUsage("Coralville2", false)

FusionPro.Composition.SetBodyPageUsage("CedarRapids2", true)

}

if (Field("version") == "NORTHLIBERTY")

{

FusionPro.Composition.SetBodyPageUsage("NorthLiberty1", true)

FusionPro.Composition.SetBodyPageUsage("CedarRapids1", false)

FusionPro.Composition.SetBodyPageUsage("NorthLiberty2", true)

FusionPro.Composition.SetBodyPageUsage("CedarRapids2", false)

}

else

{

FusionPro.Composition.SetBodyPageUsage("NorthLiberty1", false)

FusionPro.Composition.SetBodyPageUsage("CedarRapids1", true)

FusionPro.Composition.SetBodyPageUsage("NorthLiberty2", false)

FusionPro.Composition.SetBodyPageUsage("CedarRapids2", true)

}

if (Field("version") == "WASHINGTON")

{

FusionPro.Composition.SetBodyPageUsage("Washington1", true)

FusionPro.Composition.SetBodyPageUsage("CedarRapids1", false)

FusionPro.Composition.SetBodyPageUsage("Washington2", true)

FusionPro.Composition.SetBodyPageUsage("CedarRapids2", false)

}

else

{

FusionPro.Composition.SetBodyPageUsage("Washington1", false)

FusionPro.Composition.SetBodyPageUsage("CedarRapids1", true)

FusionPro.Composition.SetBodyPageUsage("Washington2", false)

FusionPro.Composition.SetBodyPageUsage("CedarRapids2", true)

}

return "";

 

I have had this work when just switching out one page, but have never tried with multiple pages. Any help would be appreciated.

Link to comment
Share on other sites

In Manage Pages > Page Usage - all pages should be set to unused.

Your Bodypages should be named according to "body page"

 

Using your example CORALVILLE has a front body page named "Coralville 1" and back "Coralville 2"-

I am assuming this is the front and back. do similar for other 3 cards.

 

If you don't set your body pages to unused they will print/process.

 

in your OnRecordStart callback rule

if (Field("version") == "CORALVILLE")
{
FusionPro.Composition.SetBodyPageUsage("Coralville 1", true)
FusionPro.Composition.SetBodyPageUsage("Coralville 2", true)
}

else if (Field("version") == "NORTHLIBERTY")
{
FusionPro.Composition.SetBodyPageUsage("NorthLiberty 1", true)
FusionPro.Composition.SetBodyPageUsage("NorthLiberty 2", true)
}

else if (Field("version") == "WASHINGTON")
{
FusionPro.Composition.SetBodyPageUsage("Washington 1", true)
FusionPro.Composition.SetBodyPageUsage("Washington 2", true)
}
else if (Field("version") == "CedarRapid")
{
FusionPro.Composition.SetBodyPageUsage("CedarRapids 1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids 2", true)
}

Edited by Leosmith
took out space in NorthLiberty - and CedarRapids...?
Link to comment
Share on other sites

I have 4 versions of a postcard. I have the version in my list to state which version to use. I have all 4 version in one PDF and have named pages 1 and 2 as body and 3-8 as unused. When I compose the file, it uses the default pages of 1 and 2 or the last 2 pages 7 and 8. For the versions that should be using pages 3-6, it is using pages 1 and 2. My script looks as follows:

if (Field("version") == "CORALVILLE")
{
FusionPro.Composition.SetBodyPageUsage("Coralville1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids1", false)
FusionPro.Composition.SetBodyPageUsage("Coralville2", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids2", false)
}
else
{
FusionPro.Composition.SetBodyPageUsage("Coralville1", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapids1", true)
FusionPro.Composition.SetBodyPageUsage("Coralville2", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapids2", true)
}
if (Field("version") == "NORTHLIBERTY")
{
FusionPro.Composition.SetBodyPageUsage("NorthLiberty1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids1", false)
FusionPro.Composition.SetBodyPageUsage("NorthLiberty2", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids2", false)
}
else
{
FusionPro.Composition.SetBodyPageUsage("NorthLiberty1", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapids1", true)
FusionPro.Composition.SetBodyPageUsage("NorthLiberty2", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapids2", true)
}
if (Field("version") == "WASHINGTON")
{
FusionPro.Composition.SetBodyPageUsage("Washington1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids1", false)
FusionPro.Composition.SetBodyPageUsage("Washington2", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapids2", false)
}
else
{
FusionPro.Composition.SetBodyPageUsage("Washington1", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapids1", true)
FusionPro.Composition.SetBodyPageUsage("Washington2", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapids2", true)
}
return "";

I have had this work when just switching out one page, but have never tried with multiple pages. Any help would be appreciated.

The main issue is that you have multiple if/else statements when you really want to use a switch statement or a big if/else if/else statement.

 

Let's assume, for example, the value of the 'version' field is 'CORALVILLE':

if (Field("version") == "CORALVILLE")                             // TRUE
{
FusionPro.Composition.SetBodyPageUsage("Coralville 1", true)      // This page is enabled
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false)    // This page is disabled
FusionPro.Composition.SetBodyPageUsage("Coralville 2", true)      // This page is enabled
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false)    // This page id disabled
}
else                                                              
{                                                                 // ---------------------
FusionPro.Composition.SetBodyPageUsage("Coralville 1", false)     // Since the first condition
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true)     // was met, this else block
FusionPro.Composition.SetBodyPageUsage("Coralville 2", false)     // does not execute.
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true)     // -----------------------
}                                                                 
if (Field("version") == "NORTHLIBERTY")                           // FALSE
{                                                                 
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty1", true)    // ------------------------
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false)    // Since version is not NORTHLIBERTY
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty2", true)    // this does not execute.
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false)    // ------------------------
}
else                                                              
{
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty1", false)   // This page is disabled
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true)     // This page is enabled
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty2", false)   // This page is disabled
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true)     // This page is enabled
}
if (Field("version") == "WASHINGTON")                             // FALSE
{
FusionPro.Composition.SetBodyPageUsage("Washington 1", true)      // -------------------------
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false)    // Since version is not WASHINGTON
FusionPro.Composition.SetBodyPageUsage("Washington 2", true)      // this does not execute.
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false)    // -------------------------
}
else
{
FusionPro.Composition.SetBodyPageUsage("Washington 1", false)     // This page is disabled
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true)     // This page is enabled
FusionPro.Composition.SetBodyPageUsage("Washington 2", false)     // This page is disabled
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true)     // This page is enabled
}                                                                 
return "";

As you can see, you'll end up with Coralville AND CedarRapids pages enabled.

 

You could simplify things a lot by replacing all of that code with:

var pages = ['Coralville', 'CedarRapids', 'NorthLiberty', 'Washington'];
var version = Field("version");
for (var i in pages) {
 var page = pages[i];
 var enable = new RegExp(page, 'i').test(version);
 FusionPro.Composition.SetBodyPageUsage(page + '1', enable);
 FusionPro.Composition.SetBodyPageUsage(page + '2', enable);
}

Link to comment
Share on other sites

I know I'm late to the party, but thought I would still share too.

 

When I have a job that has multiple pages, front and back for specific versions in one file. I set all the pages to be unused, and then I name the what ever they are called in the data file (usually called 'Key Code' field) with either '_Front' or '_Back' depending on what they are. Then I use this code as an OnRecordStart-BodyPageUsage Rule:

 

FusionPro.Composition.SetBodyPageUsage(Field("Key Code")+"_Front", true);
FusionPro.Composition.SetBodyPageUsage(Field("Key Code")+"_Back", true);

This way, there is no IF/Then else statements or switches. It either works (99% of the time, or it doesn't.

 

You can change the '_Front' and '_Back' to whatever you want, you just need to be consistent for all your pages.

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...