LyndaEngelage Posted February 22, 2016 Share Posted February 22, 2016 I'm an extreme novice at scripting. But I need a rule to suppress the line if ALL variables are empty. The following is a script I'm trying out. I need the following format to happen: "Mem_Lastname", "Mem_Firstname" "Mem_MiddleInit" Example: Doe, Joe C (I need the comma inserted between the Mem_Lastname and Mem_First name fields.) I need the whole line suppressed if all the fields are empty, not just one, including the comma. Here's the script I have so far. return [Trim(Field("Mem_Lastname")),Trim(Field("Mem_Firstname")),Trim(Field("Mem_MiddleInit"))].filter(String).join(" "); Quote Link to comment Share on other sites More sharing options...
step Posted February 22, 2016 Share Posted February 22, 2016 Here's the script I have so far. return [Trim(Field("Mem_Lastname")),Trim(Field("Mem_Firstname")),Trim(Field("Mem_MiddleInit"))].filter(String).join(" "); One nice thing about the filter method is that you can pass it a callback function to determine whether to remove the element from the array or not. For example, if you wanted to include the comma as part of the first element in your array (the lastname field), you could write a function to filter the elements if they are not strings or if the string is only a comma indicating that the last name field is empty: return [ Trim(Field("Mem_Lastname"))[color="Red"] + ','[/color], Trim(Field("Mem_Firstname")), Trim(Field("Mem_MiddleInit")) ].filter([color="red"]function(s){ return s.replace(',', ''); }[/color]).join(' '); Using the .map method would allow you to perform a function on each element of the array. This is helpful in situations that you might find yourself being repetitive in your code – with the Trim function for example. You could also add the comma to the first element of your array within that function like this: return [ Field("Mem_Lastname"), Field("Mem_Firstname"), Field("Mem_MiddleInit") ][color="red"].map(function(s,p) { return Trim(s) ? Trim(s) + (!p ? ',' : '') : ''; })[/color].filter(String).join(' '); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 23, 2016 Share Posted February 23, 2016 This should work: return Trim([Field("Mem_Lastname"), Field("Mem_Firstname")].join(' ,') + ' ' + Field("Mem_MiddleInit")); Then apply "Suppress if empty" to the line calling out the rule. Quote Link to comment Share on other sites More sharing options...
tou Posted February 24, 2016 Share Posted February 24, 2016 I think the drop down options works great in GUI paragraph settings. It's dependent the the variables instead of the lines. 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.