Jump to content

Supress page based on variable


mcantrell

Recommended Posts

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?
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...