In Marketing Cloud, there’s not really a good way of finding the original data source for a subscriber in a send — especially if you’re sending to multiple data sources for every send.
There is, however, a personalization string called _DataSourceName, outlined on the Data About the Recipient section of the Personalization Strings page in the documentation.
If you’d like to record this data, you can simply add an AMPScript variable in your email or template and set it to _DataSourceName. If your Send Log Data Extension has a column matching the variable name, it’ll get recorded for all of your sends. (Fields that start with an underscore aren’t allowed in Data Extensions, so you can’t just name it the same as the personalization string in order to record it.)
Send Log Data Extension:
If I do a single User-Initiated Send to multiple Data Extensions (DataExtension1 and DataExtension2), the following is written to the Send Log:
(I removed ListID, BatchID, SubID, TriggeredSendID, ErrorCode and SendDate columns from the above table for clarity)
Once you have this data in your Send Log Data Extension, you can correlate it with other data using a Query Activity or export for use outside Marketing Cloud.
If you need to calculate the first and last day of the current month in AMPScript, you can do it like this:
@today: 7/30/2017 8:25:22 PM
@firstDayOfThisMonth: 7/1/2017 12:00:00 AM
@nextMonth: 8/30/2017 8:25:22 PM
@firstDayOfNextMonth: 8/1/2017 12:00:00 AM
@lastDayOfThisMonth: 7/31/2017 12:00:00 AM
If you only have the full name for a subscriber and you’d like to use only the first name for a greeting, you can do something like this.
Sometimes using a Query Activity to de-duplicate data before an email send isn’t feasible. You can do it in AMPScript if you don’t mind sorting your external rows.
In this code block, you just need to use a variable to keep track of the previous value that you’ve displayed. When the current row doesn’t match the previous one, output it.
Sending tons of emails to certain email domains can be tricky, even if your sending IP address reputation is good. In Salesforce Marketing Cloud, you can utilize an Audience Exclusion Script to isolate domains for special sending treatment — like throttling or sending at a certain time of day.
Here’s an example that utilizes the AMPScript domain() function and the emailaddr personalization string that’s present in every send context.
Email #1 – Exclude emails to comcast.net domains with an exclusion script:
domain(emailaddr) == "comcast.net"
Email #2 – Exclude emails except comcast.net domains with an exclusion script:
domain(emailaddr) != "comcast.net"
Email #2 would be configured with some throttling or be deployed only at a certain time of day.
Code goes here:
This solution will work for sends to Lists, Groups or Data Extensions.
If Exclusion Scripts are not enabled for your User-Initiated or Triggered Send Definitions, SFMC support can enable them for you.
Suppose you want to output a day of the month with a proper suffix (e.g. 1st, 13th). There aren’t any formatting functions in AMPScript to do it, but you can do it with a set of if-statements:
Once you’re satisfied that it works, you can simply remove the for-loop and un-comment the set @day = Format(Now(),"dd")) line
Say you need to find the lowest of three numbers in an email — numbers you’ve retrieved from a Data Extension. Here’s one way to do it in AMPScript with a set of inline-if statements: