*** NOTE: ALL INFORMATION IS ACCURATE AT DATE OF PUBLISHING ***
I think we’ve all received marketing emails from organisations that look a little strange. Blank spaces where perhaps it should have had information populate, but the data they have isn’t accurate. Depending on the set up of a specific Dynamics 365 environment, it could be that certain fields have not been filled out on your Contact records. First Name isn’t always required, so while it’s good practice to be getting that data, make sure you add in a fall back just in case it’s missing on a record. In this post we will look at how to achieve that on an email using the Dynamics 365 Marketing App.
It might sound scary at first, but we need to use a little bit of code. This is what can be used to populate the word Customer if the First Name field is empty.
{{#if (eq contact.firstname '')}} Customer {{else if (ne contact.firstname '')}} {{contact.firstname}} {{/if}}
Let’s break it down a bit. The first line states, if the Contact First Name is equal to ” which is basically checking to see if it is empty. The eq part stands for equals. Then the line below tells the email to use the word Customer, or whatever your default fall-back word of choice would be.
{{#if (eq contact.firstname '')}} Customer
Next, we are saying if the Contact First Name does not equal ”, meaning it’s not empty, let’s do something else. The ne part stands for not equals.
{{else if (ne contact.firstname '')}}
The next line is telling the email what to use when the First Name field is not empty, which logically we will use what ever is in the First Name field on the Contact.
{{contact.firstname}}
Finally, we end the code by closing off the if statement which is done in this manner below. That stops the email from looking for any more logic in the code.
{{/if}}
We can then take this entire code and add it in to a text block on a marketing email. You can see all of the code below in Yellow with the fall-back option in Purple.
If you want to test it, you can make sure you preview it once with someone who has a first name, and once with someone who you know doesn’t. Always a good idea to have a couple of test Contacts in your environment. Here we can see Jane Doe is being used to preview the email as her. The subject includes the Contact First Name field without any code, and we see her name is displayed. We can also see it shows her name at the top of the email.
Now we preview it as Mr Smith who has no first name value on his Contact record. Notice that the Subject will just show as empty where in the example above it showed Jane’s name, so we would need to add code to make sure a fall-back is used. The top of the email shows the word Customer because our code tells the email to display that when the First Name is missing.
Consider reviewing your emails before you send them out. Make sure you really understand your data and know when values might be empty. If you are using dynamic data, having a fall-back for each option that could possibly be missing is a really good idea!
You can watch a video on this here
Check out the latest post:
Auto Assign Leads Without Code Using Lead Scoring & Work Assignment
This is just 1 of 477 articles. You can browse through all of them by going to the main blog page, or navigate through different categories to find more content you are interested in. You can also subscribe and get new blog posts emailed to you directly.
Hi Megan,
Yesterday I coincidentally tried the exact same thing with more or less the exact same code as you have shown only with the exception that I was looking at Account Name field.
However, the contacts with no data in Account Name was blocked during my test Journey with blocked reason “E-mail is missing required fields”.
Do you experience the same thing?
I have just been able to replicate the same thing. I hadn’t ever tried it before with a related record, only fields on the Contact. Going to dig in to it a little more Emil, and will report my findings!
Hi Emil. I have found the same thing as you, and confirmed that unfortunately for related data, the email is blocked if required data is missing on the record. So even when doing a check first, if the Account was missing on the Contact, the email would not send. π