Loading
Salesforce now sends email only from verified domains. Read More
Einstein and Analytics in Marketing Cloud Engagement
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          AMPscript Functions for Einstein Email Recommendations

          AMPscript Functions for Einstein Email Recommendations

          View a list of commonly used AMPscript functions for Einstein Email Recommendations.

          Use these functions to define email image templates, or for conditional formatting, data formatting, and sanitizing.

          Product Attributes

          Replace the attribute name with the attribute value of the item to recommend.

          Example
          Example

          %%AttributeName%%

          Conditional Operators

          Conditional statements allow conditional display and formatting, such as a strikethrough over the regular price when items are on sale.

          Operators where A and B can be a:

          • string
          • float
          • product attribute or exact name from your catalog, such as %%WidthInInches%%
          A > B True when A is greater than B
          A < B True when A is less than B
          A >= B True when A is greater than or equal to B
          A <= B True when A is less than or equal to B
          A == B True when A equals B
          A!= B True when A isn’t equal to B
          Example
          Example
          %%[ if a > b then ]%%
          print this if statement is true
          %%[ else ]%%
          optional line that will print if statement if false
          %%[ endif ]%%

          Logical Operators

          Use logical operators to make compound conditions in if statements. Use only one logical operator in a condition.

          && Logical And - Executes when both conditions are true.
          || Logical Or - Executes when either condition is true.
          Example
          Example

          %%[ if a > b || b > c then ]%%

          Print if at least one condition is true

          %%[ endif ]%%

          %%[ if a > b && b > c then ]%%

          Print if both conditions are true

          %%[ endif ]%%

          Conversion Functions

          ToFloat

          Appending an item attribute key with ToFloat converts the value of a string field in your catalog to a floating-point number.

          Example
          Example

          %%WidthInInches%% 12

          %%WidthInInchesToFloat%% 12.0

          LengthNum

          Appending an item attribute key with LengthNum returns the length of the value in your catalog. Use LengthNum only within the statement.

          Example
          Example

          %%[if DisplayRegularPriceLengthNum < 5 then ]%% %%ProductName%% %%[else]%% %%DisplaySalePrice%% %%[ endif ]%%

          LongestWordLength

          Append LongestWordLength to an item attribute key to convert the value to a string. This function calculates the longest word then returns a number for the length of that word.

          Example
          Example

          %%Description%%

          I love Einstein Email Recommendations

          %%DescriptionLongestWordLength%%

          15

          Display Functions

          Rating Stars

          Take the value stored in the Rating field and convert it to the number of stars where:

          • maximum_value is the highest ranking
          • color is the color of the stars

          The rating comes from the product's Rating attribute.

          Example
          Example

          %%= RatingStars(maximum_value, color) =%%

          RegularPriceMain or SalePriceMain

          Outputs the integer part of the field mapped to RegularPrice or Price for streaming updates and SalePrice.

          Example
          Example

          %%RegularPriceMain%% 34

          %%SalePriceMain%% 29

          RegularPriceFractional or SalePriceFractional

          Outputs the fractional part of the field mapped to RegularPrice or Price for using streaming updates and SalePrice.

          Example
          Example

          The following example assumes that the recommended item is regularly priced at 34.50, but on sale for 29.99.

          %%RegularPriceFractional%% 50

          %%SalePriceFractional%% 99

          ToUpcase

          Outputs the value in the catalog in uppercase.

          Example
          Example

          %%AuthorToUpcase%% MARK TWAIN

          FirstN

          Where N is a whole number, outputs the first N characters of value.

          Example
          Example

          %%AuthorFirst6%% Mark T

          Split

          Usage: SplitDAtI

          Where D is the delimiter and I is the index, splits the value returns the string at the given index. The delimiter can be longer than 1 character and the index can be negative.

          Note
          Note Currently the Split function can’t be used inside an IF condition.
          Example
          Example

          When the value for Colors is Red~Blue~Green: %%ColorsSplit~At1%% Blue

          Replace

          Usage: ReplaceAWithBEnd

          Where A is the match substring and B is the replacement substring, it replaces the matches globally and outputs the value.

          Example
          Example

          %%AuthorReplaceMarkWithSamuelEnd%% Samuel Twain

          UpTo

          Usage: UpToNByDWithOEnd

          Where N is a whole number, D is the delimiter, and O is an optional overflow text, outputs the value up to the N index of D with O appended when included. Values shorter than the limit return unaltered and values without a delimiter match within the limit returns blank.

          Example
          Example

          If the value for LongTitle is “Long~Item~Title” %%LongTitleUpTo10By~With...End%%: Long~Item…

          %%LongTitleUpTo9By~WithEnd%%: Long

          %%LongTitleUpTo4By~WithEnd%%: blank

          %%LongTitleUpTo9By~WithEnd%%: Long

          %%LongTitleUpTo20By~WithEnd%%: Long~Item~Title

          Chaining

          You can chain multiple functions together.

          Example
          Example

          For example, if Author = Mark Twain %%Author%%: Mark Twain

          %%AuthorReplaceMarkWithSamuelEndReplaceTwainWithClemensEndToUpCase%%: SAMUEL CLEMENS

           
          Loading
          Salesforce Help | Article