[SalesForce] Get name of List or Data Extension from within an Email

I am trying to figure out if I can use AMPScript in the body of an email to find out the name of the List or Data Extension the email is being sent to and then do something based on which condition is met. Does that make sense?

So basically, if I am sending an email and my Data Extension name is DE1 then do something in AMPScript. If it's DE2, do something different.

Best Answer

I think you're looking for the _DataSourceName personalization string.

This value captures any audience object sent to. This covers lists, data extensions, groups, and filters.

Usage:

%%[

if _DataSourceName == "DE1" then

  /* something for DE1 */

else

  /* something for DE2 */ 

endif

]%%

You may need to experiment with it if your send is every sent to more than one DE.

Update 2020-07-07

You can get a bunch of info about journey interactions via REST API. It'll give you all the details about the send context and email definition, etc. Technically, you could pull this data in an Automation with a Script Activity and store it in a DE. Similar to this, except with a REST call instead of WSProxy retrieve on the SOAP object.