Skip to content

Instantly share code, notes, and snippets.

@MyCueCards
MyCueCards / AMPscript-Mod-ChangeRowCollor.html
Created October 8, 2019 17:15
In Salesforce Marketing Cloud, use AMPscript's Loop and Mod to change the color of table rows based on even or odd number of Mod.
<table>
%%[FOR @i = 1 TO 10 DO]%%
%%[IF MOD(@i,2) == 1 THEN]%%
<tr>
<td style="background-color:gray;">%%=v(@i)=%%</td>
</tr>
%%[ELSE]%%
<tr>
<td>%%=v(@i)=%%</td>
</tr>
@MyCueCards
MyCueCards / RetrieveImportDefinitionResults.ssjs
Created July 26, 2019 12:58
In Salesforce Marketing Cloud, using the below will allow you to view the results of any Import Definition using SSJS in CloudPages.
// Source: https://salesforce.stackexchange.com/questions/270895/use-ssjs-to-retrieve-importdefinition-results/270934
<script runat="server">
Platform.Load("core","1.1.1");
try {
var prox = new Script.Util.WSProxy();
var cols = [
"ImportDefinitionCustomerKey",
"ImportType",
@MyCueCards
MyCueCards / CreateDEUsingArrayAndLoop.ssjs
Created July 12, 2019 00:50
In Salesforce Marketing Cloud, using the below will allow you to create multiple DE's at one time utilizing an Array and Loop.
// Source: https://salesforce.stackexchange.com/questions/268963/how-to-create-multiple-des-from-an-array-using-ssjs-via-an-automation-studio-s/268997#268997
<script runat=server>
Platform.Load("Core", "1");
var prox = new Script.Util.WSProxy();
var name = ["deRed", "deGreen", "deBlue"];
var desc = ["descRed", "descGreen", "descBlue"];
var folder = [123, 456, 789];
@MyCueCards
MyCueCards / ExcludeOpens.sql
Created May 1, 2019 18:17
In Salesforce Marketing Cloud, this is query that will exclude anyone who received a particular email by the name of the email.
SELECT
SubscriberKey,
Field1,
Field2,
Field3
FROM SomeDataExtension
WHERE SubscriberKey NOT IN (
SELECT o.SubscriberKey
FROM _Job j WITH (NOLOCK)
INNER JOIN _Open o WITH (NOLOCK) on j.JobID = o.JobID
@MyCueCards
MyCueCards / AMPscript-Loops.html
Created April 6, 2019 01:09
Example of loops in Salesforce Marketing Cloud AMPscript
<!-- AMPscript block above <HTML> -->
%%[
VAR @string
SET @string = 'PositionA1[|]PositionA2[|]PositionA3[|]PositionA4a,PositionA4b|PositionA4c,PositionA4d[^]PositionB1[|]PositionB2[|]PositionB3[|]PositionB4a,PositionB4b|PositionB4c'
SET @Array = BuildRowsetFromString(@string,"[^]")
]%%
@MyCueCards
MyCueCards / URLEncode.html
Created February 13, 2019 16:59
In Salesforce Marketing Cloud, a client is using AMPscript to pull a URL from the sending data extension (DE) into an email. The client has a Web Analytics Connector (WAC) integration, which adds parameters to the end of a URL when the email recipient opens the email. The URL generated from the WAC attempts to use a value from the sending DE, wh…
<!-- AMPscript Block -->
%%[
var @UTMstring1
set @UTMstring1 = "?utm_source=SFMC&utm_medium=email&utm_campaign"
var @UTMstring2
set @UTMstring2 = "&utm_content="
var @UTMstring3
set @UTMstring3 = "&utm_subscriber="
var @url1
@MyCueCards
MyCueCards / SSJS_FindDataExtensionLocation
Created February 13, 2019 15:04
In a Salesforce Marketing Cloud CloudPage, paste the below in an HTML block. Alter values either line 6 or line 8 to find a particular data extension. If you use 'var deName' in line 6, then you must use 'Property:"Name"' in line 7 (commenting out line 8-9). If you use 'var key' in line 8, then you must use 'Property: "CustomerKey"' in line 9 (c…
// Was found posted by Sasa Adzip in December 2018. Source = https://success.salesforce.com/ideaView?id=08730000000cIvUAAU
<script runat=server>
Platform.Load("core","1.1.5");
var deName="INSERT_DataExtensionName";
var FolderScript= DataExtension.Retrieve({Property:"Name",SimpleOperator:"equals",Value:deName});
//var key="INSERT_ExternalKeyOfDataExtension";
//var FolderScript= DataExtension.Retrieve({Property:"CustomerKey",SimpleOperator:"equals",Value:key});
var FolderID = FolderScript[0].CategoryID;
@MyCueCards
MyCueCards / AMPScript_URL_Concat.html
Created October 3, 2018 13:58
In a Salesforce Marketing Cloud email, this builds a URL when using a Google Campaign URL. This includes a couple static parameters and then a field from the sendable data extension.
%%[Set @url = concat('https://www.someurl.com?utm_source=StaticParameter1&utm_medium=StaticParameter2&utm_campaign=StaticParameter3&utm_term=',FieldName,'&utm_content=StaticParameter4')]%%
<a href="%%=RedirectTo(v(@url))=%%" target="_blank" style="font-size: 18px; font-family: Open Sans, Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; border-radius: 5px; background-color: #000000; padding: 15px 30px; border: 1px solid #000000; display: block;">Click Here &#187;</a>
@MyCueCards
MyCueCards / AllSubscriberExclude.sql
Last active February 13, 2019 15:06
In Salesforce Marketing Cloud, this query finds records within the All Subscriber List. The records it finds are those emails addresses, which match the email within SomeDataExtension. There is an extra parameter to exclude a string.
SELECT sde.*
FROM SomeDataExtension sde
INNER JOIN _ListSubscribers l ON sde.SubKey = l.SubscriberKey
WHERE l.ListID = '000'
AND sde.SubKey = l.SubscriberKey
AND sde.Email = l.EmailAddress
AND sde.Email NOT LIKE '%string here%'
@MyCueCards
MyCueCards / GTM_GetEmailFromSession.js
Created July 19, 2018 17:16
In Google Tag Manager, get a variable session storage. This is entered into GTM as "Customer JavaScript" variable. The result is also a variable as a "1st Party Cookie."
function ()
{
var result = '';
if(typeof(Storage) !== 'undefined')
{
if (typeof(window.sessionStorage._enterCookieName) !== 'undefined')
{
result = window.sessionStorage._enterCookieName + '';