Fletch Posted December 3, 2014 Share Posted December 3, 2014 I have a line of text that will contain a variable, only if that field in the CSV file is not empty. If the field is empty, I need line of text to not appear. (example.."Thank you for your donation of <<donation field>>) If <<donation field>> contains a number, then both the line of text and the variable print, if the <<donation field>> is empty, I need the line of text to not print. Any ideas? Quote Link to comment Share on other sites More sharing options...
jimmyhartington Posted December 3, 2014 Share Posted December 3, 2014 Hi Fletch I would make a text-rule, which looks at the length of the field Donation. Like this: if (Field("Donation").length == 0) { return ""; } else { return "Thank you for your donation of " + Field("Donation"); } So if the length of field Donation is 0 it returns nothing. Else it returns the text + field Donation Quote Link to comment Share on other sites More sharing options...
Fletch Posted December 3, 2014 Author Share Posted December 3, 2014 I think that will work. However, my conditional variable falls within a sentence. Here it is "Your last gift of _______ was truly appreciated, and I hope you’ll consider a similar, or slightly increased, gift this year." Can you tell me whaty I need to do to have text before and after the condtional variable? Quote Link to comment Share on other sites More sharing options...
Fletch Posted December 3, 2014 Author Share Posted December 3, 2014 I figured it out. if (Field("LASTDONATIONAMOUNT").length == 0) { return "you."; } else { return "you. Your last gift of $" + Field("LASTDONATIONAMOUNT") + " was truly appreciated, and I hope you'll consider a similar, or slightly increased, gift this year "; } Quote Link to comment Share on other sites More sharing options...
step Posted December 3, 2014 Share Posted December 3, 2014 You don't have to use code for this. You could just type that line of text and insert the variable in the text frame. Then select that line, click paragraph, and "Suppress if: containing empty variables." On the other hand, if you're wanting to do it with code, you could do something like this: var donation = Trim(Field("Donation")); var result = (donation) ? "Your last gift of " + donation + " was truly appreciated, and I hope you'll consider a similar, or slightly increased, gift this year." : ""; return result; 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.