#1
|
|||
|
|||
![]()
I am trying to create a banner with a few fields and some size changes based upon one of the fields.
I have 3 sizes for banners (18x12, 60x30, 72x36) based upon the number of years selected 1-5 = 18x12 10-15 = 18x12 20-25 = 60x30 30+ = 72x36 With 3 layouts for the background Style 1 Style 2 Style 3 The field for "Years of service" is entered in manually while the background is based on a pick list of the 3 styles. I believe that OnRecordStart would be my best bet for this, but I'm not getting the result I was hoping for. I have set all pages to "Body, unused" and then I get no records to show. Originally I had all pages set to "Body" and each page displayed, which was not what I was looking for either. I couldn't find anything that was similar enough for me to build off of on the forum yet, so I decided to post my javascript here and maybe someone would be able to find out what I am missing. Thanks for the look and any and all help! var Background = Field("Background"); if (Field("Years of Service") >=1 && Field("Years of Service")<= 5) + Field("Background") == "Style 1"; return ("Style 1 18x12"); if (Field("Years of Service") >=10 && Field("Years of Service")<= 15) + Field("Background") == "Style 1"; return ("Style 1 18x12"); if (Field("Years of Service") >=20 && Field("Years of Service")<= 25) + Field("Background") == "Style 1"; return ("Style 1 60x30"); if (Field("Years of Service") >=30 + (Field("Background") == "Style 1")); return ("Style 1 72x36"); if (Field("Years of Service") >=1 && Field("Years of Service")<= 5) + Field("Background") == "Style 2"; return ("Style 1 18x12"); if (Field("Years of Service") >=10 && Field("Years of Service")<= 15) + Field("Background") == "Style 2"; return ("Style 2 18x12"); if (Field("Years of Service") >=20 && Field("Years of Service")<= 25) + Field("Background") == "Style 2"; return ("Style 2 60x30"); if (Field("Years of Service") >=30 + (Field("Background") == "Style 2")); return ("Style 2 72x36"); if (Field("Years of Service") >=1 && Field("Years of Service")<= 5) + Field("Background") == "Style 3"; return ("Style 3 18x12"); if (Field("Years of Service") >=10 && Field("Years of Service")<= 15) + Field("Background") == "Style 3"; return ("Style 3 18x12"); if (Field("Years of Service") >=20 && Field("Years of Service")<= 25) + Field("Background") == "Style 3"; return ("Style 3 60x30"); if (Field("Years of Service") >=30 + (Field("Background") == "Style 3")); return ("Style 3 72x36"); switch(Background) { case "Style 1 18x12": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",true); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 1 60x30": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",true); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 1 72x36": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",true); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 2 18x12": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",true); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 2 60x30": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",true); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 2 72x36": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",true); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 3 18x12": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",true); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 3 60x30": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",true); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); break; case "Style 3 72x36": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",true); break; } |
#2
|
|||
|
|||
![]() Quote:
Just looking at this part, your variable "Background" is always going to equal the Field("Background"), so the switch will never work. Let's say Field("Background") is equal to "18x12", and you are trying to make the variable to equal the return of your 'if' statement, correct. You could change your variable to be... Code:
var Style1A = "Style 1 18x12"; var Style1B = "Style 1 18x12"; Code:
if (Field("Years of Service") >=1 && Field("Years of Service")<= 5) + Field("Background") == "Style 1"; return Style1A; if (Field("Years of Service") >=10 && Field("Years of Service")<= 15) + Field("Background") == "Style 1"; return Style1B; Code:
case "Style1A": FusionPro.Composition.SetBodyPageUsage("Style 1 18x12",true); FusionPro.Composition.SetBodyPageUsage("Style 1 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 1 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 2 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 2 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 2 72x36",false); FusionPro.Composition.SetBodyPageUsage("Style 3 18x12",false); FusionPro.Composition.SetBodyPageUsage("Style 3 60x30",false); FusionPro.Composition.SetBodyPageUsage("Style 3 72x36",false); |
#3
|
|||
|
|||
![]()
Thanks for the look. That makes a lot of sense. I will give it a try!
|
#4
|
||||
|
||||
![]() Quote:
Quote:
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"); } 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);
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#5
|
|||
|
|||
![]()
Ste Pennell, you are almost correct with the syntax. I don't just have 3 pages of the specific sizes (18x12, 60x30 & 72x36), but 9 pages, one for each size and style due to text frames being completely different throughout.
The years will only be entered in values between 1-5, 10-15, 20-25 or 30 +, none of the in-between values. Each year range determines a size for the banner and adding the style from a drop down list would determine which page of the template to be used. Does this make more sense? |
#6
|
|||
|
|||
![]()
Scotts, for the most part this script works except once I remove the switch, I get a syntax error on the first 'case'. I'm trying to work through it now and will update with fix once it is working.
|
#7
|
||||
|
||||
![]() Quote:
Quote:
Code:
var background = Field("Background") || 'Style 1'; switch (Field("Years of Service")) { case '1-5': case '10-15': size = '18x12'; break; case '20-25': size = '60x30'; break; default: size = '72x36'; } FusionPro.Composition.SetBodyPageUsage(background + " " + size, true);
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#8
|
|||
|
|||
![]()
Yes, the years will only be entered in those specific ranges (company policy for these items).
I've gone ahead and added this into the OnRecordStart and all records are composed on the 72x36 (default size) template, no matter what number of years you are putting in. This is the first code that I have put in that actually produces 1 record instead of the 9 or 0 from before, and I do understand a little of what the code is doing. The styles are coming through just fine though. I appreciate all the help on this. Albeit still a little confused, my knowledge base is growing on this. Hopefully I have this working today. Thanks again step! Last edited by gdellaiera; May 24th, 2018 at 08:46 AM.. |
#9
|
|||
|
|||
![]()
Step,
I have one question: Why add a default size and no numerical case for the largest size? Everything else makes sense to me but this. And no matter what size I change to, the output will only remain that size when I run any record through it. Thanks for the explanation. default: size = '72x36'; |
#10
|
||||
|
||||
![]() Quote:
That's leads me to believe that you haven't accurately described the values your "Years of Service" field contain. I can't really help you any further without seeing an example of your data/template.
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
![]() |
Tags |
fusion pro, javascript, onrecordstart |
Thread Tools | Search this Thread |
Display Modes | |
|
|