2

I am using AMSCRIPT to personnalize some sender details in an email block at the end of the email. This block contains several lines :

  • name of the account
  • first name, last name,
  • phone
  • email adress
  • postal adress

I would like to avoid to display a break line if the fields are empty.

I had tried a code based on researchs I did in StackEchange but when I test it, I still have break lines in the empty fields. I have no doubt I am doing something wrong.

Here is the code I used on the beginning of the email :

%%[ 
var @accountname, @lastname, @firstname, @phone, @emailadress, @postaladress

SET @accountname = AttributeValue("Opportunity:Account:Name")
SET @lastname = AttributeValue("Opportunity:NomCommercial__c")
SET @firstname = AttributeValue("Opportunity:PrenomCommercial__c")
SET @phone = AttributeValue("Opportunity:TelephoneCommercial__c")
SET @emailadress = AttributeValue("Opportunity:EmailCommercial__c")
SET @postaladress = Concat(@Opportunity:Account:BillingStreet, "", @Opportunity:Account:BillingPostalCode, "", @Opportunity:Account:BillingCity)

%%=iif(not empty(@accountname),concat(@accountname,"<br/>"),"")=%%
%%=iif(not empty(@firstname),@firstname,"")=%%%%=iif(not empty(@lastname ),concat("",@lastname),"")=%%<br/>
%%=iif(not empty(@phone),concat(@phone,"<br/>"),"")=%%
%%=iif(not empty(@emailadress),concat(@emailadress,"<br/>"),"")=%%
%%=iif(not empty(@postaladress),concat(@postaladress,"<br/>"),"")=%%

endif 
]%%

On the email body at the bottom of the email I had added the output function :

%%=v(@accountname)=%%
%%=v(@firstname)=%% %%=v(@lastname)=%%
%%=v(@phone)=%%
%%=v(@emailadress)=%%
%%=v(@postaladress)=%%

I do not know :

  1. how to apply the iif condition that I had put on the beginning of the email with my v function
  2. and if I have to use the v function to display only the fields that are not empty and not to display break lines between lines if the fields are empty.

Thanks for your precious help

3
  • 1
    just to be sure. depending on how your lower code snippet is entered into the email - unless you are entering the lower snippet into a plain HTML block (but e.g. a free form), it DOES contain line breaks between the %%=v()=%% functions. May 11 at 12:06
  • Hi @JonasLamberty, I was using a text email thats'why but the code worked perfectly. I had put in on snippet block in a email and it worked. May 18 at 10:36
  • ok :) then i'll formulate that as an answer. May 18 at 10:48

1 Answer 1

1

Judging from your comment:

The line breaks that were physically entered between your variables are the problem. Since you previewed as text - pure text emails understand and display them as line breaks, while a HTML block / code snippet would only interpret actual <br>s as such >> hence this problem only occurred in plain text.

Maybe it's personal taste, but I would encourage to leave HTML out of AMPScript functions (iif / concat), myself I usually just write physical HTML and output variables between AMPscript blocks:

Something like:

%%[
/* establish variables like in your code ... */

/* concat first & last; trims leading and trailing spaces (in case one of them is empty, the space vanishes) */

SET @fullname = trim(concat(@firstname," ",@lastname))

/* conditional section where logic is separate from output */
if not empty(@accountName) THEN]%%%%=v(@accountname)=%%<br/>%%[endif]%%
%%[if not empty(@fullname) THEN]%%%%=v(@fullname)=%%<br/>%%[endif]%%
%%[if not empty(@phone) THEN]%%%%=v(@phone)=%%<br/>%%[endif]%%
%%[if not empty(@emailadress) THEN]%%%%=v(@emailadress)=%%<br/>%%[endif]%%
%%[if not empty(@postaladress) THEN]%%%%=v(@postaladress)=%%<br/>%%[endif]%%
endif 
]%%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.