PDA

View Full Version : Supress page based on variable


mcantrell
April 8th, 2009, 06:53 AM
I currently have a 3 page document. Based on the data supplied, I need the template to print only 2 of the three pages. It could be 1 & 2, 1 & 3, or 2 & 3. Is there a way to supress a page or convert it to an unused page through a rule?

Dan Korn
April 8th, 2009, 08:10 AM
Please refer to the section "How to switch body pages during composition" in the FusionPro Rules System Guide.

mcantrell
April 9th, 2009, 10:43 AM
I have referred to the Rules guide. Below is the code I have in OnRecordStart. It gived me an error that SetBodyPageUsage is undefined.

if (Field("Tech") == String("Both"))
{
SetBodyPageUsage("TA",true);
SetBodyPageUsage("TOPO",true);
SetBodyPageUsage("Blank",false);
}

if (Field("Tech") == String("TA"))
{
SetBodyPageUsage("TA",true);
SetBodyPageUsage("TOPO",false);
SetBodyPageUsage("Blank",true);
}

if (Field("Tech") == String("TOPO"))
{
SetBodyPageUsage("TA",false);
SetBodyPageUsage("TOPO",true);
SetBodyPageUsage("Blank",true);
}

return "";



If I add var SetBodyPageUsage is says SetBodyPageUsage is not a function and all other fields in my document remain blank even on preview. Any ideas what I am missing?

Thanks!

Dan Korn
April 9th, 2009, 11:55 AM
The correct syntax of the function is FusionPro.Composition.SetBodyPageUsage(name, usage). For example:
FusionPro.Composition.SetBodyPageUsage("TA",true);
Note also that if you set all of the pages to Unused in the Page Usage dialog, you only need to enable the ones you want. So the rule can simply do this:
if (Field("Tech") == "Both")
{
FusionPro.Composition.SetBodyPageUsage("TA",true);
FusionPro.Composition.SetBodyPageUsage("TOPO",true);
}
else if (Field("Tech") == "TA")
{
FusionPro.Composition.SetBodyPageUsage("TA",true);
FusionPro.Composition.SetBodyPageUsage("Blank",true);
}
else if (Field("Tech") == "TOPO")
{
FusionPro.Composition.SetBodyPageUsage("TOPO",true);
FusionPro.Composition.SetBodyPageUsage("Blank",true);
}
else
ReportError("Can't set pages for Tech: " + Field("Tech"));
Note here also that we're handling the exception case. This can be further reduced to:
switch (Field("Tech"))
{
case "Both":
FusionPro.Composition.SetBodyPageUsage("TA",true);
FusionPro.Composition.SetBodyPageUsage("TOPO",true);
break;
case "TA":
FusionPro.Composition.SetBodyPageUsage("TA",true);
FusionPro.Composition.SetBodyPageUsage("Blank",true);
break;
case "TOPO":
FusionPro.Composition.SetBodyPageUsage("TOPO",true);
FusionPro.Composition.SetBodyPageUsage("Blank",true);
break;
default:
ReportError("Can't set pages for Tech: " + Field("Tech"));
}
Or, even more succinctly:
if (Field("Tech") == "Both")
{
FusionPro.Composition.SetBodyPageUsage("TA",true);
FusionPro.Composition.SetBodyPageUsage("TOPO",true);
}
else
FusionPro.Composition.SetBodyPageUsage(Field("Tech"), true);
Where the FusionPro.Composition.SetBodyPageUsage function will throw an appropriate error if the named page is not found.