gdellaiera Posted May 22, 2018 Share Posted May 22, 2018 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; } Quote Link to comment Share on other sites More sharing options...
scotts Posted May 22, 2018 Share Posted May 22, 2018 I am trying to create a banner with a few fields and some size changes based upon one of the fields. var Background = Field("Background"); if (Field("Years of Service") >=1 && Field("Years of Service")<= 5) + Field("Background") == "Style 1"; return ("Style 1 18x12"); switch(Background) { case "Style 1 18x12": } 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... var Style1A = "Style 1 18x12"; var Style1B = "Style 1 18x12"; And your return to be... 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; And your SetBodyPageUsage to be...without the switch 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); Hope this helps. Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted May 22, 2018 Author Share Posted May 22, 2018 Thanks for the look. That makes a lot of sense. I will give it a try! Quote Link to comment Share on other sites More sharing options...
step Posted May 23, 2018 Share Posted May 23, 2018 You could change your variable to be... var Style1A = "Style 1 18x12"; var Style1B = "Style 1 18x12"; Both of those variables are set to the same value. Is that intentional? And your return to be... 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; 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); Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted May 23, 2018 Author Share Posted May 23, 2018 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? Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted May 23, 2018 Author Share Posted May 23, 2018 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. Quote Link to comment Share on other sites More sharing options...
step Posted May 24, 2018 Share Posted May 24, 2018 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. Yes, I know. But you only have 3 size options. The switch statement determines which size to use. From there, the style is appended to the size to create the page name. The years will only be entered in values between 1-5, 10-15, 20-25 or 30 +, none of the in-between values. Are you saying that the value of the "Years of Service" field is a string value representing a range of numbers (like "1-5") or just that the user will never enter a number outside of those specified ranges (like 6)? The latter of which shouldn't make a difference and the code should still work. But, if the values are string ranges, you could modify the code like this: 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); 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? Right, and again, that's what the code I posted is doing. It determines the size needed based on the "Years of Service" and adds the style selected from the drop down list to it. Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted May 24, 2018 Author Share Posted May 24, 2018 (edited) 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! Edited May 24, 2018 by gdellaiera Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted May 25, 2018 Author Share Posted May 25, 2018 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'; Quote Link to comment Share on other sites More sharing options...
step Posted May 29, 2018 Share Posted May 29, 2018 Why add a default size and no numerical case for the largest size? Everything else makes sense to me but this. Because cases have been set for all other scenarios. If none of the cases evaluated to true, then it stands to reason that the only remaining option would be the 72x36 size. Check out this reference on switch statements to get a better understanding. And no matter what size I change to, the output will only remain that size when I run any record through it. 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. Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted May 29, 2018 Author Share Posted May 29, 2018 (edited) 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!Banner Data.txt Edited May 30, 2018 by gdellaiera Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted June 4, 2018 Author Share Posted June 4, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.