0

I want to use only one template for sending to different sendable Data Extensions with different fields. How can I manage it when I set the user data like this

%%[
Var @COUNTRYCODE, @LANGUAGECODE, @SFID, @EMAIL, @FIRSTNAME

DE1:

Set @LANGUAGECODE = TRIM(Language) 
Set @COUNTRYCODE = TRIM(Country) 
Set @FIRSTNAME = FirstName
Set @SFID = TRIM(Salesforce_ID)
Set @EMAIL = TRIM(EmailAddress)   

DE2:

Set @LANGUAGECODE = TRIM(Lead:Email_Newsletter_language__c) 
Set @COUNTRYCODE = TRIM(Lead:Website_Country__c) 
Set @SFID = Lead:Id
Set @EMAIL = Lead:Email

Thanks!

Oliver


I now let the Marketing Manager set the name of the Sendable Data Extension over an Additional Email Attribute

%%[ /* Set user date */

Var @COUNTRYCODE, @LANGUAGECODE, @SFID, @EMAIL, @VERSION, @DataExtension

SET @VERSION = _DataSourceName Set @DataExtension = "%%__AdditionalEmailAttribute3%%"

IF INDEXOF(@VERSION, @DataExtension) > 0 THEN Set @LANGUAGECODE = LOWERCASE(TRIM(ATTRIBUTEVALUE("Language"))) Set @COUNTRYCODE = TRIM(ATTRIBUTEVALUE("Country")) Set @SFID = TRIM(ATTRIBUTEVALUE("Salesforce_ID")) Set @EMAIL = TRIM(ATTRIBUTEVALUE("EmailAddress")) ELSE Set @LANGUAGECODE = TRIM(ATTRIBUTEVALUE("Lead:Email_Newsletter_language__c")) Set @COUNTRYCODE = TRIM(ATTRIBUTEVALUE("Lead:Website_Country__c")) Set @SFID = ATTRIBUTEVALUE("Lead:Id") Set @EMAIL = ATTRIBUTEVALUE("Lead:Email") ENDIF ]%%

2
  • Can you please be more specific? How are you sending your emails? Manually, by triggered send or by automation?
    – Eduard
    Commented Jul 16, 2018 at 9:37
  • DE1 are the Newsletter Subscribers. We send to them manually. DE2 is a Salesforce Data Event from Journey Builder. The Email is triggered automatically.
    – Oliver
    Commented Jul 16, 2018 at 9:39

1 Answer 1

2

Assuming that the rest of the content outside of the AMPScript variable setting is the same and that the newsletter DE (DE1) will always be the same or the name will be similar enough, what you could do is set a variable based on %%_DataSourceName%% Personalization String to differentiate between the setting of your vars.

For example:

%%[
SET @Version = AttributeValue(_DataSourceName)

IF INDEXOF(@Version, "Newsletter") > 0 THEN
/* This is assuming that Newsletter will appear in DE1's name */

Set @LANGUAGECODE = TRIM(ATTRIBUTEVALUE("Language")) 
Set @COUNTRYCODE = TRIM(ATTRIBUTEVALUE("Country")) 
Set @FIRSTNAME = ATTRIBUTEVALUE("FirstName")
Set @SFID = TRIM(ATTRIBUTEVALUE("Salesforce_ID"))
Set @EMAIL = TRIM(ATTRIBUTEVALUE("EmailAddress")) 

ELSE
/* it is safer to just have the trigger as an else statement, rather than a second if */

Set @LANGUAGECODE = TRIM(ATTRIBUTEVALUE("Lead:Email_Newsletter_language__c")) 
Set @COUNTRYCODE = TRIM(ATTRIBUTEVALUE("Lead:Website_Country__c")) 
Set @SFID = ATTRIBUTEVALUE("Lead:Id")
Set @EMAIL = ATTRIBUTEVALUE("Lead:Email")

ENDIF
]%%

By setting the name of the DE to @Version, you are able to do a 'Contains' via IndexOf() to search for a naming convention you use for the newsletter to differentiate how each field is set.

I wrapped each inside of an ATTRIBUTEVALUE() function to help handle null values - I honestly do not remember if the Salesforce Data fields will work inside of this (I believe they do) so if it throws an error or shows up empty, try removing the attribute value on the non-newsletter version.

2
  • Hi Gortington, thanks for the reply. What can I do when the names of the sendable DEs change.? Thanks
    – Oliver
    Commented Jul 27, 2018 at 12:49
  • That is the reason I used IndexOf() instead of equals. As long as the word 'Newsletter' is used in the DEs name, it will trigger the appropriate condition. You can replace 'Newsletter' with whatever repetitive unique convention you want though. Commented Jul 27, 2018 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .