Re: Email script to hide fields when value is blank

Simone_Toit
Level 2

Email script to hide fields when value is blank

I have added email script to pull through custom fields into a table using Mytokens - see below - this lead only has 3 funds - the maximum # of funds is 9.

The details of your other super funds*

Fund name

Member Number

Code

Fund 1

1

11

Fund 2

2

22

Fund 3

3

33

${lead.otherfundname4}

${lead.otherfundnumber4}

${lead.uSI4}

${lead.otherfundname5}

${lead.otherfundnumber5}

${lead.uSI5}

${lead.otherfundname6}

${lead.otherfundnumber6}

${lead.uSI6}

${lead.otherfundname7}

${lead.otherfundnumber7}

${lead.uSI7}

${lead.otherfundname8}

${lead.otherfundnumber8}

${lead.uSI8}

${lead.otherfundname9}

${lead.otherfundnumber9}

${lead.uSI9}

I need to hide the tokens when the field value is blank so that the table resizes. Can anyone help with this?

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Email script to hide fields when value is blank

#foreach( $fund in [1..9] )

#if( !$lead["otherfundname${fund}"].isEmpty() )

<tr><td>${lead["otherfundname${fund}"]}</td><td>${lead["otherfundnumber${fund}"]}</td><td>${lead["uSI${fund}"]}</td>

#end

#end

Simone_Toit
Level 2

Re: Email script to hide fields when value is blank

Thanks Sanford Whiteman​ I tried copying and pasting your code above underneath my other email script and it didn't work.

SanfordWhiteman
Level 10 - Community Moderator

Re: Email script to hide fields when value is blank

(a) "It didn't work" isn't enough info to go on.

(b) Why would you paste my code underneath your other script? I can't undo the unwanted output from your script.  I'm showing you how to create the conditional output: looping over the possible variables and only outputting the non-empty ones.

Simone_Toit
Level 2

Re: Email script to hide fields when value is blank

Sorry, I'm not a developer so finding this challenging. When I replaced the email script with your code, the email populated as per below.

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

${lead["otherfundname${fund}"]}

${lead["otherfundnumber${fund}"]}

${lead["uSI${fund}"]}

SanfordWhiteman
Level 10 - Community Moderator

Re: Email script to hide fields when value is blank

Did you check all 27 of the fields in the right-hand side tree on Script Editor?

Kirstie_Olah
Level 2

Re: Email script to hide fields when value is blank

Hi there,

Did you work this out as I have the same query and issue I need to solve for a campaign. Can you show me what you did to get it to work.

 

Many thanks.

SanfordWhiteman
Level 10 - Community Moderator

Re: Email script to hide fields when value is blank

See my answer on your other post.