Marketing Cloud is often the user of data owned in another system – like a Salesforce Sales Cloud instance. This can make it challenging for SFMC Admins to standardize variable names. As I’ve mentioned in many of my talks – one of the first things you should do when you start an integration is to talk with the developer in charge of the data integration and stress that all fields use a standardized naming convention. This will keep you from having Email, EmailAddy, EmailAddress, Email Address, etc. And while a good relationship with the other teams can help with data standardization – it can not protect you from ALL potential issues.
If all of your audiences start in Marketing Cloud or are all coming from the same source, you can standardize the name of the field that will hold the SubscriberKey.
If you are pairing Marketing Cloud with another Salesforce product with Marketing Cloud Connector, you must use the Salesforce Contact or Lead ID as your subscriberkey. Depending on what object you are using to build your audiences – the field that holds the Salesforce Contact ID could be named ID, or LeadID, or ContactID. Even more problematic is when you utilize Salesforce Data as your entry audience source for a journey. That then introduces even more variations of what that field could be named.
While this on its own is more confusing than problematic – it can create an issue with your header and footer. Remember, in order to do any lookups or data retrieval, you have to set a variable with the user’s ID.
One simple solution would be to have a different header template for each variation of the name. This is easy upfront but can cause lots of issues down the line. For instance, if someone builds an email on the wrong template, it could error out within your journey. Another challenge arrives when you need to update your header/footer – you would have to update & support multiple copies – which can be error-prone and time-consuming.
But to unify your header, you have to add some logic so that it knows which version of the ID to use. This is where ATTRIBUTEVALUE() comes in. Attributevalue returns the value of a subscriber attribute, but that isn’t why we want to use it. We want to use Attributevalue for what it does when that subscriber attribute does not have a value.
You see, Fields without values are not all populated equally. There are 3 common types of fields without values –
- NULL – means nothing, is recognized as no value – but it is not always recognized as an empty field.
- “” – looks like nothing, is not considered a value – except it is still considered a not empty field.
- Empty – is empty – therefore no value.
While they all look like they should mean the same thing, they don’t work the same way.
Now you could name all three in your IF statement:
%%[ IF @variablename is NULL or @variablename=="" or empty(@variablename) then ]%%
But that is a lot of pieces and can get a little crazy when you start adding layers to it.
An easier solution is to use ATTRIBUTEVALUE() as it will return a value if there is one, and an Empty field if there isn’t – i.e., converts empty, null, “” to all be empty fields.
One other advantage of using AttributeValue() is that it can help you avoid a runtime error proactively. If you call a Profile Attribute or DE Column name that doesn’t exist in your sending audience, your email send will terminate with a runtime error. (For those of you who have not encountered this issue- it looks like your send looks like it is taking forever to process and then suddenly cancels itself and will show as canceled in tracking.)
So what is ATTRIBUTE VALUE?
The AttributeValue() function returns the value of a subscriber attribute.
It can be used in Emails, Mobile Pushes, and CloudPages.
It works with :
- Email Subscriber Profile Attributes
- Sendable Data Extension Fields
- Journey Builder Entry Source Attributes
- MobileConnect List Attributes
- MobilePush Attributes
For this use case, we will be pairing ATTRIBUTEVALUE() with the Journey Builder Entry Source Attributes.
As you know, Journey Builder takes the information passed to it and copies it into a data extension (‘DE’) specifically for that journey – known as Journey Data. This DE uses the names of the fields in the audience source DE.
When the audience source is Salesforce Data – the Subscriber Key field can have multiple variations when it comes to names. For instance:
Using AttributeValue() we can normalize the data and ensure that everything is returned in the same format. And again, I am more interested that it returns the same format/value for when there isn’t a value.
Step 1: Compile a list of all the name variations
Step 2: Set a variable for each variation with ATTRIBUTEVALUE()
Step 3: Use an IF/Then to set a value for your final ID variable by checking which variation is not empty.
See below for a full example
DEFINITION OF PARTS —
FieldName = This is the attribute value or DE column name you want to return a value. It can be passed as a @variable or in “string format”.
Advanced Example 1 – Using AttributeValue to set ID for Lookups/Retrieves:
/* Set Subscriber ID */ set @ID_SubscriberKey=AttributeValue("SubscriberKey") set @ID_CampaignMember=AttributeValue("CampaignMember:Id") set @ID_CampaignMember2=AttributeValue("CampaignMember:Common:Id") set @ID_Contact=AttributeValue("Contact:ID")
if not empty(@ID_SubscriberKey) then set @sfid=@ID_SubscriberKey elseif not empty(@ID_CampaignMember) then set @sfid=@ID_CampaignMember elseif not empty(@ID_CampaignMember2) then set @sfid=@ID_CampaignMember2 elseif not empty(@ID_Contact) then set @sfid=@ID_Contact else set @LookUpID = RetrieveSalesforceObjects('Contact', 'Id', 'email','=', emailaddr) if rowcount(@LookUpID)>0 then set @IDRow = Row(@LookUpID,1) set @sfid = Field(@IDRow, 'Id') endif endif
Salesforce Developer – AttributeValue()
AMPscript Guide – AttributeValue()
AMPscript Guide – Leveraging the AttributeValue and Empty Functions