How to make an audience skip if a particular field is null using velocity code?

Hemaprasath_Jin
Level 2

How to make an audience skip if a particular field is null using velocity code?

For example if I have a field A from custom object and I'm displaying it in the email content. In-order to neglect those who have null values in that particular field(A) I want to skip it using a velocity code, is this feasible or do I need to do it via campaign or flow setup.

6 REPLIES 6
Nicholas_Manojl
Level 9

Re: How to make an audience skip if a particular field is null using velocity code?

I'm not sure I fully understand your question.

#if (customObject.get(0).fieldA)
This only shows if they have a value in fieldA
#end‍‍‍

or potentially you mean, how do I stop the  null value from showing the reference? You can prepend your field reference with an exclamation mark:

$!customObject[0].fieldA

SanfordWhiteman
Level 10 - Community Moderator

Re: How to make an audience skip if a particular field is null using velocity code?

This only shows if they have a value in fieldA

It shows if they have a value other than Boolean false or null in the first entry in the list.

So: not the same as "do they have a non-null in any of the entries in the list".

In order to check that some value is non-null you must iterate over the entire list.

But I think what this thread is about is suppressing the email entirely, which cannot be done with Velocity. It has to be done using Smart List qualification.

Hemaprasath_Jin
Level 2

Re: How to make an audience skip if a particular field is null using velocity code?

Gotcha, Is it possible to use that token in the flow-step and skip that email?

SanfordWhiteman
Level 10 - Community Moderator

Re: How to make an audience skip if a particular field is null using velocity code?

The Velocity token? No, Velocity never works in Flow steps, period. You'd use the standard Smart List filters: Has Object, constraining on the field value.

Hemaprasath_Jin
Level 2

Re: How to make an audience skip if a particular field is null using velocity code?

@nicholas Thanks for your solution, but I don't want to stop null value instead I want to skip that customer from getting email, so in the else part I need to write a function to skip him from getting email

Amit_Jain
Level 8 - Community Advisor

Re: How to make an audience skip if a particular field is null using velocity code?

You have to use a filter in the smart list of the smart campaign to skip the user from receiving the email.  But in case you have multiple flow actions in that smart campaign and you just want to skip this particular flow actions which is sending email, you can create a separate smart list for these users and use that smart list as condition in the flow step like below:

pastedImage_1.png

Velocity script can be used to manipulate the email content but it can not skip the email altogether. Hope it will help.