Jump to content

Suppress if empty in rule


cecprepress

Recommended Posts

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

Link to comment
Share on other sites

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(" ");

Link to comment
Share on other sites

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(" ");

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.

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