Jump to content

If all three numbers are populated show alert

Recommended Posts

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.



Link to comment
Share on other sites

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
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.

Link to comment
Share on other sites

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!


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...