cecprepress Posted February 21, 2013 Share Posted February 21, 2013 This will probably be an easy fix. I'm using Acrobat Pro 9.5 and FusionPro Desktop 7.2. I have a line that contains 3 fields and some spaces (First Name, Middle Name, Last Name. If all 3 fields are empty, I want to suppress that line. But only if all 3 are empty. Since this won't work via just using the setting in the text box I'm trying to do it with a rule, but I keep getting a syntax error (Line 2, it highlights the "!" in "!=". What am I doing wrong? The goal is to output "First Middle Last" (with spaces between) and only suppress the line if all 3 are empty. Below is the rule as I have it set up currently: var NamesOut = ""; if (Trim(Field("First Name"))) != "") { NamesOut += Field("First Name"); } if (Trim(Field("Middle Name")) != "") { if (NamesOut != "") { NamesOut += Field("Middle Name"); } if (Trim(Field("Last Name")) != "") { if (NamesOut != "") { NamesOut += Field("Last Name"); } else { NamesOut += Field("First Name"); } } return NamesOut; Thanks, Rick Quote Link to comment Share on other sites More sharing options...
scubajbc Posted February 21, 2013 Share Posted February 21, 2013 (edited) I believe you have 1 too many parentheses in line 2 try... if (Trim(Field("First Name")) != "") { Edited February 21, 2013 by scubajbc fixed grammar Quote Link to comment Share on other sites More sharing options...
cecprepress Posted February 21, 2013 Author Share Posted February 21, 2013 I knew it was easy...I looked for that exact problem and didn't see it. Guess it needed a fresh set of eyes. Thanks! Quote Link to comment Share on other sites More sharing options...
step Posted February 21, 2013 Share Posted February 21, 2013 You could simplify your if statements like this: var result = ""; result += (Field("First Name") != "") ? Trim(Field("First Name")) + " " : "" ; result += (Field("Middle Name") != "") ? Trim(Field("Middle Name")) + " " : "" ; result += (Field("Last Name") != "") ? Trim(Field("Last Name")) + " " : "" ; return Left(result,result.length-1); Or you could accomplish the same thing in less code using a for loop: var names = [Trim(Field("First Name")),Trim(Field("Middle Name")),Trim(Field("Last Name"))]; for (var i=0; i<3; i++) { if (names[i] == "") { names.splice(i,1); i--; } } return names.join(" "); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 21, 2013 Share Posted February 21, 2013 Or you could accomplish the same thing in less code using a for loop: var names = [Trim(Field("First Name")),Trim(Field("Middle Name")),Trim(Field("Last Name"))]; for (var i=0; i<3; i++) { if (names[i] == "") { names.splice(i,1); i--; } } return names.join(" "); You can do it all in one line in FusionPro 8.0 or later: return [Trim(Field("First Name")),Trim(Field("Middle Name")),Trim(Field("Last Name"))].filter(String).join(" "); Quote Link to comment Share on other sites More sharing options...
step Posted February 25, 2013 Share Posted February 25, 2013 You can do it all in one line in FusionPro 8.0 or later: return [Trim(Field("First Name")),Trim(Field("Middle Name")),Trim(Field("Last Name"))].filter(String).join(" "); Now, that's fancy! 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.