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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old May 29th, 2018, 06:05 AM
gdellaiera gdellaiera is offline
Regular Contributor
 
Join Date: Nov 2016
Posts: 78
Default Re: Switching pages with on record start

I've added my data sheet. There are 4 variables: FirstName, LastName, Years of Service & Style. Not too much as these is very little information needed from the customer.

I'm going to read more about the switch and try to figure out where I am getting lost. Thanks again for all of the help!
Attached Files
File Type: txt Banner Data.txt (246 Bytes, 5 views)

Last edited by gdellaiera; May 30th, 2018 at 11:19 AM..
Reply With Quote
  #12  
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

Quote:
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:
Code:
/**
 * 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:
Code:
// 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
Reply

Tags
fusion pro, javascript, onrecordstart

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 07:27 AM.


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