Jump to content

Page Counts and Blank Pages


EX_BCBS

Recommended Posts

Sorry if this is a re-pst, but I'm trying to simply count the number of pages in a record and pad with blank pages to get to a divisor of 4. I've got a handful of pages that are either included or excluded based on user selections in the web form. Can FP calculate page counts OnRecordStart where I would make the SetBodyPageUsage call for the blank page?
Link to comment
Share on other sites

Well, if you're controlling which pages are activated in your OnRecordStart rule, then you can simply create a counter variable and add one to it every time you set a page's usage to true. Then you can simply add a blank page to your PDF and call SetBodyPageUsage for it in the same rule.
Link to comment
Share on other sites

Using a counter variable works.....some of the time. After I get the page count, I'm using a switch statement to call the correct number of blank pages based on the page count. Sometimes the correct pages appear, sometimes it doesn't. Is there something in my rule that could cause this or have I stumbled upon a bug?

 

// Set Inserts and Forms

var PageCount = 5;

if ((Field("Blue 365"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("Blue 365","true")

PageCount = PageCount + 1

}

if ((Field("Provider"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("Find a Provider 1","true")

PageCount = PageCount + 1

}

if ((Field("Provider"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("Find a Provider 2","true")

PageCount = PageCount + 1

}

if ((Field("Prevention"))==String("Yes"))

{

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

PageCount = PageCount + 1

}

if ((Field("Improvement"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("Health Improvement","true")

PageCount = PageCount + 1

}

if ((Field("Coaching"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("Health Coaching","true")

PageCount = PageCount + 1

}

if ((Field("HRA"))==String("Yes"))

{

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

PageCount = PageCount + 1

}

if ((Field("QFL"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("Quit For Life","true")

PageCount = PageCount + 1

}

if ((Field("HIPAA"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("HIPAA 1","true")

PageCount = PageCount + 1

}

if ((Field("HIPAA"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("HIPAA 2","true")

PageCount = PageCount + 1

}

if ((Field("HIPAA"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("HIPAA 3","true")

PageCount = PageCount + 1

}

if ((Field("GEF"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("GEF 1","true")

PageCount = PageCount + 1

}

if ((Field("GEF"))==String("Yes"))

{

FusionPro.Composition.SetBodyPageUsage("GEF 2","true")

PageCount = PageCount + 1

}

 

// Set correct number of blank pages

return PageCount

switch (PageCount)

{

case (PageCount = 5):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

FusionPro.Composition.SetBodyPageUsage("Blank 3","true")

case (PageCount = 6):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

case (PageCount = 7):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

case (PageCount = 8):

case (PageCount = 9):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

FusionPro.Composition.SetBodyPageUsage("Blank 3","true")

case (PageCount = 10):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

case (PageCount = 11):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

case (PageCount = 12):

case (PageCount = 13):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

FusionPro.Composition.SetBodyPageUsage("Blank 3","true")

case (PageCount = 14):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

case (PageCount = 15):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

 

case (PageCount = 16):

case (PageCount = 17):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

FusionPro.Composition.SetBodyPageUsage("Blank 3","true")

case (PageCount = 18):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

FusionPro.Composition.SetBodyPageUsage("Blank 2","true")

case (PageCount = 19):

FusionPro.Composition.SetBodyPageUsage("Blank 1","true")

case (PageCount = 20):

}

Link to comment
Share on other sites

I think the problem is this line:

return PageCount

The "return" statement stops execution of the rule before all of your other calls to activate the blank pages. As the message in the Validate dialog notes, the return value is ignored at composition time, but the effect of the return statement itself is still present.

 

It can be useful to have intermediate returns like this for debugging purposes while you're editing the rule, but you have to remember to delete them or comment them out before saving the rule and composing. Alternatively, you can guard such statements with the FusionPro.inValidation property, like so:

if (FusionPro.inValidation)
 return PageCount;

This causes the return to only happen at validation time in the Rule Editor, and not at composition time.

 

Or, you can use the Print function to write a message to your composition log (.msg) file, like so:

Print("PageCount is " + PageCount);

This also has no effect on the composition output, just the log file.

 

Anyway, I would write the rule something like this:

var PageCount = 5;

function ActivatePageFromField(fieldName, pageName)
{
   var activate = (Field(fieldName) == "Yes");
   FusionPro.Composition.SetBodyPageUsage(pageName, activate)
   if (activate)
       PageCount++;
}

ActivatePageFromField("Blue 365", "Blue 365");
ActivatePageFromField("Provider", "Find a Provider 1");
ActivatePageFromField("Provider", "Find a Provider 2");
ActivatePageFromField("Prevention", "Prevention");
ActivatePageFromField("Improvement", "Health Improvement");
ActivatePageFromField("Coaching", "Health Coaching");
ActivatePageFromField("HRA", "HRA");
ActivatePageFromField("QFL", "Quit For Life");
ActivatePageFromField("HIPAA", "HIPAA 1");
ActivatePageFromField("HIPAA", "HIPAA 2");
ActivatePageFromField("HIPAA", "HIPAA 3");
ActivatePageFromField("GEF", "GEF 1");
ActivatePageFromField("GEF", "GEF 2");

if (FusionPro.inValidation)
   return PageCount;

// Add blank pages to get a total multiple of 4:
var numBlanks = (4 - (PageCount % 4)) % 4; // modulus (remainder) operator trick
for (var i = 1; i <= numBlanks; i++)
   FusionPro.Composition.SetBodyPageUsage("Blank " + i, true);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...