Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 22nd, 2018, 11:02 AM
slivingston slivingston is offline
Forum n00b
 
Join Date: Jul 2017
Posts: 5
Default OnRecordStart Switching Pages

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("Coralville 1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false)
FusionPro.Composition.SetBodyPageUsage("Coralville 2", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false)
}
else
{
FusionPro.Composition.SetBodyPageUsage("Coralville 1", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true)
FusionPro.Composition.SetBodyPageUsage("Coralville 2", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true)
}
if (Field("version") == "NORTHLIBERTY")
{
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false)
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty2", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false)
}
else
{
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty1", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true)
FusionPro.Composition.SetBodyPageUsage("NorthLiber ty2", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true)
}
if (Field("version") == "WASHINGTON")
{
FusionPro.Composition.SetBodyPageUsage("Washington 1", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false)
FusionPro.Composition.SetBodyPageUsage("Washington 2", true)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false)
}
else
{
FusionPro.Composition.SetBodyPageUsage("Washington 1", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true)
FusionPro.Composition.SetBodyPageUsage("Washington 2", false)
FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", 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.
Reply With Quote
  #2  
Old February 22nd, 2018, 03:14 PM
Leosmith Leosmith is offline
Junior Community Member
 
Join Date: Jun 2015
Location: Saint Paul
Posts: 41
Default Re: OnRecordStart Switching Pages

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
Code:
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)
}
__________________
Leo Smith - Novice
FusionPro VDP Creator 10
Adobe Pro CC
Windows 7

Last edited by Leosmith; February 22nd, 2018 at 03:17 PM.. Reason: took out space in NorthLiberty - and CedarRapids...?
Reply With Quote
  #3  
Old February 22nd, 2018, 04:48 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: OnRecordStart Switching Pages

Quote:
Originally Posted by slivingston View Post
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:
Code:
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':
Code:
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:
Code:
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);
}
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #4  
Old February 23rd, 2018, 09:02 AM
slivingston slivingston is offline
Forum n00b
 
Join Date: Jul 2017
Posts: 5
Default Re: OnRecordStart Switching Pages

Thank you very much for your help. Worked like a charm.
Reply With Quote
  #5  
Old February 23rd, 2018, 10:36 AM
scotts scotts is offline
Junior Community Member
 
Join Date: Feb 2011
Location: Zeeland, MI, USA
Posts: 41
Default Re: OnRecordStart Switching Pages

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:

Code:
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:33 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.