Jump to content

Variable within a conditional variable.


Fletch

Recommended Posts

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?
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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;

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