Rollins Print Services Posted October 10, 2015 Share Posted October 10, 2015 Our BC may contain two of the three number options. telephone #, Fax #, Cell #. But it may not contain them all because of space limitations. I wanted to try and have a script that will show an alert when all three are populated, but do nothing if just two are used. I'm new to the whole java process and am learning but can't seem to get this one. Any thoughts or ideas? Thanks for the help in advance. Doug Quote Link to comment Share on other sites More sharing options...
step Posted October 12, 2015 Share Posted October 12, 2015 Sure you can do that pretty easily: var numbers = [ Field('phone'), // phone field or rule Field('cell'), // cell field or rule Field('fax') // fax field or rule ].filter(String); var warning = "** Only 2 numbers allowed **"; // warning message return (numbers.length > 2) ? warning : numbers.join('<br>'); The above code makes use of an array ('numbers') which is compromised of 3 positions: "phone", "cell", and "fax" fields (in this example) but if you have separate rules for formatting each number, you can insert those there as well. Then the empty positions (your fields) in the array are removed using the filter method. Then, the return line is a conditional (ternary) operator that says: "if the 'numbers' array has 3 elements in it, return the warning – but if it has less than 3 elements in it, join them with a line break tag." That being said, you could also look into applying "Copyfit" to the text frame you're using to remedy your "space limitations." One final note: Java is to JavaScript as Ham is to Hamster. FusionPro rules are written in JavaScript. Java is a completely different language. Quote Link to comment Share on other sites More sharing options...
Rollins Print Services Posted October 14, 2015 Author Share Posted October 14, 2015 Please forgive me for the confusion of terminology. I should know better than that, I was aware they are not the same. Thank you so much for the code and the explanation. I have a lot to learn and I appreciate the support! Quote Link to comment Share on other sites More sharing options...
step Posted October 14, 2015 Share Posted October 14, 2015 Please forgive me for the confusion of terminology. I should know better than that, I was aware they are not the same. It's all good, Doug! It happens all the time (I mean, there's a webpage dedicated to it) but I just wanted to point it out in case you weren't aware so you wouldn't google how to do something in Java and then try to apply it to FP. Thank you so much for the code and the explanation. I have a lot to learn and I appreciate the support! Anytime! 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.