https://www.myampscript.com Wed, 25 May 2022 23:32:54 +0000 en hourly 1 https://wordpress.org/?v=6.3.2 Dynamic Sender Profiles with AMPscript https://www.myampscript.com/dynamic-sender-profiles-with-ampscript/ https://www.myampscript.com/dynamic-sender-profiles-with-ampscript/#comments Wed, 25 May 2022 18:44:11 +0000 https://www.myampscript.com/?p=963 Overview

Have you ever wanted to customize the from name and from email in your Marketing Cloud emails? If so this demo is meant for you. This feature uses AMPscript mixed with some account configuration in order to make this work. For this demo, we want to pull dynamic from name and from email from our content DE and use that within our new custom Dynamic Sender Profile. Objects you’ll be building are:

  • Create 1 test sendable DE.
  • Create 1 test content DE.
  • Create 1 Dynamic From Name code snippet.
  • Create 1 Dynamic From Email code snippet.
  • Create 1 Dynamic Sender Profile.
  • Create 1 test email to preview and send with.

Sendable Data Extension

This is the sendable data extension. You’ll notice that each subscriber has a language preference. We’ll match the subscribers language preference against the language field in the content DE so that we can return the correct From Name and From Email to use in our Dynamic Sender Profile. You can download the sample data for this tutorial by clicking here.


Content Data Extension

This is the content data extension. You’ll notice that each row contains custom content for dynamic from name and from email. We’ll use the subscribers language preference to return the correct from name and from email to use inside our Dynamic Sender Profile. You can download the sample data for this tutorial by clicking here.


Dynamic From Name Code Snippet

This code snippet uses the subscriber’s language preference to do a lookup on the content DE to pull back the dynamic from name, which is then used in the new Dynamic Sender Profile. You’ll also notice that immediately following the lookup we are outputting that value to the snippet via %%=v(@fromName)=%%.


Dynamic From Email Code Snippet

This code snippet uses the subscriber’s language preference to do a lookup on the content DE to pull back the dynamic from email, which is then used in the new Dynamic Sender Profile. You’ll also notice that immediately following the lookup we are outputting that value to the snippet via %%=v(@fromEmail)=%%.


Dynamic Sender Profile Setup

This is wher you will create your new custom dynamic sender profile. You can create a new sender profile by navigating to: Admin > Send Management > Sender Profiles > Create. This is where we want to use the TreatAsContent() and ContentByKey() to insert our DynamicFromName and DynamicFromEmail code snippets into the From Name and From Email fields. Please use the two strings below:

  • %%=TreatAsContent(ContentBlockByKey(‘DynamicFromName’))=%%
  • %%=TreatAsContent(ContentBlockByKey(‘DynamicFromEmail’))=%%

Important Note!

It’s important that your dynamic from email addresses use a authenticated @domain address. Otherwise, your email sends will more than likely fail on the backend. For example, if the authenticated @domain for your account is @company.com and your dynamic from email addresses use some other @domain.com then you’ll run into deliverability issues. Please make sure to consider the following items below before using Dynamic Sender Profiles.

  • Please ensure all your dynamic from email addresses use an authenticated @domain address.
  • Please consult your deliverability specialist beforehand to minimize risk.
  • Please consult your account executive to ensure enhanced sender profiles is enabled on your account.

Gallery

]]>
https://www.myampscript.com/dynamic-sender-profiles-with-ampscript/feed/ 1
Looping through XML with AMPscript Advanced Level https://www.myampscript.com/looping-through-xml-with-ampscript-advanced-level/ https://www.myampscript.com/looping-through-xml-with-ampscript-advanced-level/#comments Thu, 20 Jan 2022 16:47:37 +0000 https://www.myampscript.com/?p=919 AMPscript Looping

This example shows how to loop through xml payloads using AMPscript. We’ll break this process into few different steps.

  1. Review the xml data structured.
  2. Review the data extension.
  3. Writing logic that loads the xml into the email.
  4. Write logic to include safeguards for error handling.
  5. Write logic to loop through xml nodes.
  6. Review the code output.

Reviewing the XML Data Structure

The goal is to write AMPscript logic that will loop through all nodes. This is a screenshot of what the XML payload looks like. You’ll notice that the entire <catalog> contains multiple <book> nodes that we’ll eventually loop through with AMPscript. Additionally, you’ll also notice that for every <book> node it contains data for that specific book’s ID, Author, Title, and Genre. You can download the sample data for this tutorial by clicking here.


Reviewing the Data Extension

The goal is to write AMPscript logic that will load and loop through this XML from within the email. You’ll notice that we have three use cases mocked up below. The 2nd and 3rd use case represent negative test scenarios. This means that our AMPscript safeguards should raise an error whenever there is missing and or incomplete data. You can download the sample data for this tutorial by clicking here.

  1. Subscriber with complete XML data.
  2. Subscriber with no XML data.
  3. Subscriber with incomplete XML data.

Looping through XML with AMPscript

This example shows you how you can loop through XML with AMPscript. In this example you’ll notice that we are doing the following:

  1. Taking the XML data from the [XML] field in the sendable DE and assigning that to a variable called @XML
  2. Write AMPscript logic that uses the BuildRowSetFromXML() function to then build rows based on however many <book> nodes are available.
  3. Write AMPscript logic that sets up safeguards to handle missing XML data.
  4. Write AMPscript logic that sets up safeguards to handle incomplete XML data.
  5. Write AMPscript logic so that the the BuildRowSetFromXML() function and the AMPscript for loop only run if the XML data exists.

Gallery

]]>
https://www.myampscript.com/looping-through-xml-with-ampscript-advanced-level/feed/ 3
AMPscript LookupRows Function Intermediate Level https://www.myampscript.com/ampscript-lookuprows-function-intermediate-level/ https://www.myampscript.com/ampscript-lookuprows-function-intermediate-level/#comments Thu, 30 Dec 2021 22:10:31 +0000 https://www.myampscript.com/?p=873 Content LookupRows

This function returns a rowset from a data extension where the field matches the specified value. This function returns a maximum of 2000 rows. To better control the number or order of rows returned please use the LookupOrderedRows function instead. Using the LookupOrderedRows function enhances script performance. But for this example, we will focus on how to use the standard LookupRows function.

  • LookupRows(1, 2, 3)

Content Lookup Benefits

Here are some reasons why you might want to consider using a Content Lookup approach:

  • The content lookup approach works best when emails need to support multiple languages and or segments.
  • The content lookup approach allows the dynamic email to scale to evolving business needs.
  • The content lookup approach allows your email to scale to evolving business needs.
  • The content lookup approach allows us to separate email content from the email framework which makes it easier to add, remove, or modify content without having to touch code.

Sendable Data Extension

This is the sendable data extension. You’ll notice that each subscriber has a language preference. We’ll use the language preference from the sendable DE to match against the language field from the content DE so that we can return the correct row in our LookupRows() script. You can download my sample data for the sendable DE by clicking here.


Content Data Extension

This is the content data extension. You’ll notice that each row contains content that is specific to a language. We’ll use the subscribers language preference to return the correct translated content to use within the email. Simply add more rows so that your email can scale to support additional languages. You can download my sample data for the content DE by clicking here.


LookupRows Function

This example returns copy from the content DE based on subscribers language preference.


Gallery

]]>
https://www.myampscript.com/ampscript-lookuprows-function-intermediate-level/feed/ 1
AMPscript Format Functions Beginner Level https://www.myampscript.com/ampscript-format-functions-beginner-level/ https://www.myampscript.com/ampscript-format-functions-beginner-level/#comments Tue, 21 Dec 2021 14:41:59 +0000 https://www.myampscript.com/?p=856 AMPscript Format Functions

AMPscript DateTime functions allow us to manipulate display format, perform math functions, and control email content using static, dynamic, and real-time values. Formatting functions provide a powerful tool set for converting various data types to formatted strings and numbers.

  • FormatDate(1, 2, 3, 4)
  • FormatCurrency(1, 2, 3, 4)
  • FormatNumber(1, 2, 3)
  • Format(1, 2, 3, 4)

Format Date Function

This function formats a specified string as a date value for a specified format pattern and locale.

Example
%%=FormatDate(1, 2, 3, 4)=%%


Format Currency Function

This function formats a specified string as a currency value for a specified locale.

Example
%%=FormatCurrency(1, 2, 3, 4)=%%


Format Number Function

This function formats a specified string as a number for a specified locale.

Example
%%=FormatNumber(1, 2, 3)=%%


Format Function

This function formats a string into a specified format pattern and locale. You’ll want to use this function for date and time formatting that requires a locale setting.

Example
%%=Format(1, 2, 3, 4)=%%


Gallery

]]>
https://www.myampscript.com/ampscript-format-functions-beginner-level/feed/ 1
AMPscript DateTime Functions Beginner Level https://www.myampscript.com/ampscript-datetime-functions-beginner-level/ https://www.myampscript.com/ampscript-datetime-functions-beginner-level/#comments Tue, 14 Dec 2021 20:09:53 +0000 https://www.myampscript.com/?p=822 AMPscript DateTime Functions

AMPscript DateTime functions allow us to manipulate display format, perform math functions, and control email content using static, dynamic, and real-time values with:

  • Now(1) Campaign Sends
  • Now(1) Triggered Sends
  • DateAdd(1, 2, 3)
  • DateDiff(1, 2, 3)
  • DateParse(1, 2)
  • DatePart(1, 2)

Now(1) Function – Campaign Sends

The Now() function is used to capture the system DateTime at the time of send. The system uses Central Standard Time and does not adjust for Daylight Savings Time. Now() returns a dynamic date that will update when using in an email VAWP (View As Web Page) link and or landing pages. You’ll want to use Now(1) to preserve the date at the time of send.

Example
%%=Now(1)=%%


Now(1) Function – Triggered Sends

Now(1) doesn’t work as expected for triggered sends. When used in a triggered send, it returns the last time the triggered-send-definition was published. If you need to maintain the accurate send time and date in a trigger (i.e. for VAWP links,) use this workaround: Add a date field to the triggered DE (name it something like “DateAdded”) and auto-populate it with the current date. This sets that field to the date/time the record was added to the DE (the date/time the triggered email was sent).


Date Add Function

The DateAdd() function is used to increase or decrease the date time value. It can be used with a date object or with the Now() function. You need to date objects in order for this to work.

Example
%%=DateAdd(1, 2, 3)=%%


Date Diff Function

The DateDiff() function returns the difference between two date values. Always use DateDiff() when comparing DateTime values otherwise they will be compared as string values.

Example
%%=DateDiff(1, 2, 3)=%%


Date Parse Function

The DateParse() function is used to convert a string into a DateTime object. Date might be provided as a string in the incorrect format so DateParse() converts it into a DateTime object in the proper format.

Example
%%=DateParse(1, 2)=%%


Date Part Function

The DatePart() function isolates specific elements of a date object. This function is useful when having to break apart a date to format it around specific business requirements. It’s especially helpful converting dates to support other languages.

Example
%%=DatePart(1, 2)=%%


Gallery

]]>
https://www.myampscript.com/ampscript-datetime-functions-beginner-level/feed/ 1
AMPscript Math Functions Beginner Level https://www.myampscript.com/ampscript-math-functions-beginner-level/ https://www.myampscript.com/ampscript-math-functions-beginner-level/#comments Fri, 10 Dec 2021 18:20:44 +0000 https://www.myampscript.com/?p=703 AMPscript Math Functions

The math functions below allow us to add, subtract, divide, and multiply numbers in Marketing Cloud Emails, Landing Pages, SMS/MMS Messages, and Push Notifications. You can write complex math equations to calculate numbers on the fly using these functions.

  • Add(N1,N2)
  • Subtract(N1, N2)
  • Multiply(N1, N2)
  • Divide(N1, N2)
  • Mod(N1, N2)

Add Function

The Add() function in AMPscript is used to add two numeric constants or two variables with a numeric value set.

Example
%%=Add(N1,N2)=%%


Subtract Function

The Subtract() function in AMPscript is used to subtract two numeric constants or two variables with a numeric value set.

Example
%%=Subtract(N1,N2)=%%


Multiply Function

The Multiply() function in AMPscript is used to multiply two numeric constants or two variables with a numeric value set.

Example
%%=Multiply(N1,N2)=%%


Divide Function

The Divide() function in AMPscript is used to divide two numeric constants or two variables with a numeric value set.

Example
%%=Divide(N1,N2)=%%


Mod Function

The Mod() function in AMPscript is used to find the remainder between two numeric constants or two variables with a numeric value set.

Example
%%=Mod(N1,N2)=%%


Gallery

]]>
https://www.myampscript.com/ampscript-math-functions-beginner-level/feed/ 1
AMPscript Basics Part 2 https://www.myampscript.com/ampscript-basics-part-2/ https://www.myampscript.com/ampscript-basics-part-2/#comments Fri, 10 Dec 2021 14:23:23 +0000 https://www.myampscript.com/?p=684 AMPscript Functions

Functions are self contained blocks of code that perform specific tasks. Functions usually take in data, process it, and return a result. Learn more on the next slide. Functions are written like this: functionName(1)

Section functionName
This section is the unique name that describes the function.

Section ()
The values you insert into the parentheses is what the function evaluates.

Section 1
This section represents the parameters that can be used inside this function. Multiple parameters are separated by commas.


AMPscript Block Delimiters

To identify AMPscript, it must be surrounded by opening and closing delimiters or it will be ignored. AMPscript uses two types, Block Delimiters and Inline Delimiters. This section focuses on Block Delimiters. Block Delimiters are useful when you have several lines of AMPscript code. They can be placed anywhere in the email but most developers will include this at the top. This way AMPscript logic placed at the top of the email will cascade down the email when using it in the HTML markup.


AMPscript Inline Delimiters

To identify AMPscript, it must be surrounded by opening and closing delimiters or it will be ignored. AMPscript uses two types, Block Delimiters and Inline Delimiters. This section focuses on Inline Delimiters. Inline Delimiters are useful when you need to call a function outside of an AMPscript block. You can do this by using the inline method. Simply insert %%= script goes here =%% into your HTML code.


AMPscript Comments

Every good developer knows why it’s important to add comments to your code. AMPscript comments are ignored by the application and do not show up in the final deployment. This differs from HTML comments. HTML comments can still be viewed after deployment by inspecting the source code. AMPscript comments are processed before the send and thus removed at the time of send. This can be useful if you want to ensure comments are absolutely hidden from subscribers.


Gallery

]]>
https://www.myampscript.com/ampscript-basics-part-2/feed/ 1
AMPscript Basics Part 1 https://www.myampscript.com/ampscript-basics-part-1/ https://www.myampscript.com/ampscript-basics-part-1/#comments Thu, 09 Dec 2021 00:17:03 +0000 https://www.myampscript.com/?p=614 What is AMPscript?

AMPscript is a Salesforce proprietary scripting language that interacts with Marketing Cloud emails, landing pages, SMS and MMS messages and push notifications. By learning the AMPscript language, you can do any of the following:

Can add personalized, unique content for each subscriber.
• Example Subject Line: Hello, First Name!

Display content based on certain conditions.
• Example Subject Line #1: Hello, First Name!
• Example Subject Line #2: Hello, Valued Customer!

Format Date Values
• Example Date: Date might provide a date as “MM/DD/YYYY” but we want it to show as “Month Day, Year” instead.


AMPscript Syntax

As mentioned, AMPscript is a scripting language, and when you learn any new language, you first have to master how it works. AMPscript uses the following langauge elements.

• Constants
• Attributes and Data Extension Values
• Variables (or Keywords)


AMPscript Constants

Numeric Values
Numeric constant values consist of one or more digits. They are formatted as unquoted numerals. They can include 1 decimal point and an introductory minus sign for negative numbers. Commas, are not permitted.

String Values
A string is a set of one or more letters, numbers, spaces or special characters. These constant values must be surrounded (delimited) by double or single quotes. They can also include the same type of delimiting quote inside by doubling it.

Boolean Values
Boolean constant values must use the words true or false. They are not surrounded by quotes. They are also NOT case sensitive.

NULL Values
A NULL value represents the absence of a value. The use of a NULL value is just a pointer, which is pointing to nowhere in memory.


Attributes & Data Extension Values

Attributes and data extension values refer to any content held inside a subscriber list or a data extension. If the name includes a space or special character, you must surround it with opening and closing brackets. Best practice to always include the opening and closing brackets when using attributes. This adds consistency when troubleshooting.

Example Use Case
Let’s say you’re building an email and the data extension you’re sending to has two fields called “Birthdate” and “FirstName”. The example below demonstrates how you can pull the values from those fields to use within your email.


Variables (or Keywords)

A variable is a storage location for information you want to reference later on. A variable includes two parts, an identifier and a value. The Identifier is a symbolic name you want to use. The Value is the information you want to store.

Declaring Variables
When you declare a variable, you are telling the system that the variable exists. By default, whenever you declare a variable that variable will be set to NULL.
• Example: VAR @FullName

Setting Variables
When you’re ready to set a variable you can assign values to it.
• Example: SET @FullName = “John Doe”


Gallery

]]>
https://www.myampscript.com/ampscript-basics-part-1/feed/ 1
AMPscript String Functions Intermediate Level https://www.myampscript.com/ampscript-string-functions-intermediate/ https://www.myampscript.com/ampscript-string-functions-intermediate/#comments Tue, 07 Dec 2021 20:37:36 +0000 https://www.myampscript.com/?p=594 Overview

As we dive into more complex AMPscript logic we may come across situations where we need to manipulate string values to achieve different things. We can do this by using the following functions listed below:

Replace(1, 2, 3)
Length(1)
IndexOf(1, 2)
Substring(1, 2, 3)
Concat(1, 2)


Examples

Replace Function
There may be instances where a client is using dynamic email copy to deliver highly personalized emails to its users. The client realizes they did not update their data and accidently left references to 2007 in their dynamic email copy. To save the client time, we can dynamically convert 2007 to 2008 using the Replace function.

Length Function
There may be an instance where the client wants to show the last four characters of a subscriber’s credit card number. In this situation, we would use the Length function to determine how many characters a subscriber’s credit card number is. Then you’d use Length in conjunction with the Substring function to show the last four digits.

Substring Function
Returns the portion of the specified string starting with the specified character position and no longer than the specified length. There may be an instance where the client wants you to show a portion of the string value. In this case, you’d want to use Substring to handle that requirement.

Concat Function
Concatenates the strings specified in the arguments. Include as many values as necessary. It’s common for clients to ask us to append certain tracking variables to the end of a click thru URL. We can use the Concat function to simply attach query string variables to links.

IndexOf Function
Sometimes clients ask us to hide and show email content based off keywords in their dynamic data. For example, the client sends a monthly newsletter to their subscribers. They want us to show a special coupon for premium users. Premium users are identified when the word premium is used in the cust_status field. The client wants you to show this special coupon when cust_status contains the word premium.


Gallery

]]>
https://www.myampscript.com/ampscript-string-functions-intermediate/feed/ 1
AMPscript String Functions Beginner Level https://www.myampscript.com/ampscript-string-functions-beginner/ https://www.myampscript.com/ampscript-string-functions-beginner/#comments Wed, 11 Mar 2020 03:00:03 +0000 http://localhost/mira/?p=33 Overview

As we dive into more complex AMPscript logic we may come across situations where we need to manipulate string values to achieve different things. We can do this by using the following functions listed below:

  • Lowercase(1)
  • Uppercase(1)
  • Propercase(1)
  • Trim(1)
  • Empty(1)

Examples

Lowercase Function
An example of when we might use this function is if a client wants us to render email copy in all lowercase letters. For example, let’s say that the client’s data contains values in in all uppercase letters. We can use the Lowercase function to convert the client’s data from uppercase to lowercase without having to manually update data in the data extension.


Uppercase Function
An example of when we might use this function is if a client wants us to render email copy in all uppercase letters. For example, let’s say that the client’s data contains values in all lowercase letters. We can use the Uppercase function to convert the client’s data from lowercase to uppercase without having to manually update data in the data extension.

Propercase Function
An example of when we might use this function is if a client wants us to render email copy using proper case formatting. For example, let’s say that the client’s data contains values in all uppercase letters. We can use the ProperCase function to convert the client’s data from uppercase to proper case without having to manually update data in the data extension.

Trim Function
There may be instances where the client provides data with undesired spaces. An example might be if the client has a field in the sendable data extension called fname. The client accidently uses “  John  ” in that field rather than “John”. In order to clean this up prior to using it in the email we use the Trim function to strip out unwanted spaces before and after the data value.

Empty Function
This function is used often to evaluate whether a variable is empty or not. You’ll notice that this function is combined with other functions to evaluate and personalize content. In this example, we check to see if @name is empty or not. If so, then set the @name variable to “Valued Customer” to use as a fallback.


Gallery

]]>
https://www.myampscript.com/ampscript-string-functions-beginner/feed/ 1