View Single Post
Old June 4th, 2018, 10:02 AM
gdellaiera gdellaiera is offline
Regular Contributor
Join Date: Nov 2016
Posts: 78
Default Re: Switching pages with on record start

Originally Posted by step View Post
Both of those variables are set to the same value. Is that intentional?

I don't think that will work. If I'm understanding correctly, Gdellaiera is trying to determine which page to use here based on the "Years of Service" field and appending the style to the end of the string. So the correct syntax would be:
 * When the vale of the "Years of Service" field is between 10-15, the
 * page size should be 18x12 regardless of the style selected in the
 * "Background" field. So set the `page` variable to the appropriate size
 * and append the style to the end to dynamically cover all three styles. 
if (Field("Years of Service") >=10 && Field("Years of Service")<= 15) {
  var page = "18x12 " + Field("Background");
I think a better way to accomplish this task would be:
// Get the "Years of Service" value and cast it as an integer for comparisons.
// Default the value to `1` when the field is empty.
var yearsOfService = Int(Field("Years of Service")) || 1;
// Get the style value from the "Background" field.
// Default to `Style 1`.
var background = Field("Background") || 'Style 1';
// Use a switch statement to determine which page size we should be using. We'll
// set the `size` variable to the first expression that evaluates to `true`.
switch (true) {
  // Check to see if the `yearsOfService` is 15 or less. If it is, we can set the
  // size to 18x12 and none of the other expressions in this `switch` will be evaluated.
  case yearsOfService <= 15: size = '18x12'; break;
  // If the `yearsOfService` is more than 15, we will check to see if the
  // `yearsOfService` field is 25 or less. If it is, set the size to 60x30.
  case yearsOfService <= 25: size = '60x30'; break;
  // If neither of the two previous cases were true, that means the `yearsOfService`
  // is greater than 25, so we can set the size to 72x36.
  default: size = '72x36';
// Since you've already set all of the body pages to `false`, you only need to
// enable the correct page.
FusionPro.Composition.SetBodyPageUsage(background + " " + size, true);
Can I ask one question here: Where is 'size' coming from? There is no variable in the document named size (or rule) and the only reference to any number is in the page name.
Reply With Quote