Adding default value when first name personalization is blank | Community
Skip to main content
March 25, 2021
Question

Adding default value when first name personalization is blank

  • March 25, 2021
  • 2 replies
  • 2095 views

Hello,

How can I add a default value to my firstName personalization in my email, such as "Valued Customer" if firstName is empty? Right now, it shows as a blank space followed by a comma).

 

<span class="nl-dce-field mobile_header_text nl-dce-done" id="span161662637290731" data-nl-expr="/context/profile/firstName" data-nl-type="string" data-contenteditable="false" data-nl-format="datetime">First name (firstName)</span>

 

Thanks in advance.

 

Terri

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Adobe Employee
April 5, 2021

you could define a dynamic content and then use a condition "firstname is not empty" and the default value

April 12, 2021
@bisswang - thanks! I'll give it a whirl. 🙂
Xyborg
April 8, 2021

I would go with Ramon's solution, but you could use a content block as well.

 

Here is the code of one we have already in place in our ACS:

 

<% // Displays a greeting formula appropriate for the profiles' fields // populated in the database (first name, last name and title) // The following table defines the formula to use in each case // (#0 is replaced with the title, #1 with the first name and #2 with the last name) var aGreetings = // **bleep** Fir Las ['Hello,' , // 'Hello,' , // X 'Hello,' , // X 'Hello #1 #2,' , // X X 'Hello #0,' , // X 'Hello #0 #2,' , // X X 'Hello #0,' , // X X 'Hello #0 #1 #2,']; // X X X var aField = [context.profile.salutation, // field corresponding to #0 context.profile.firstName, // field corresponding to #1 context.profile.lastName]; // field corresponding to #2 var iIndex = 0, iCount = aField.length; for( i=0 ; i<iCount ; i++ ) { if( aField[i] != '' ) iIndex += Math.pow(2,(iCount-i-1)); } var sToDisp = aGreetings[iIndex]; sToDisp = sToDisp.replace(/#0/, aField[0]); sToDisp = sToDisp.replace(/#1/, aField[1]); sToDisp = sToDisp.replace(/#2/, aField[2]); document.write(sToDisp); %>

 

You can use the code above and modify it to only use the first name if exist.

April 12, 2021
@xyborg - thanks so much for the info. I will check out Ramon's first and then yours.