12 Days of Scriptmas - 2022
Published on 12/09/2021
As 2022 draws to a close, it’s time to open up the door on the 2022 edition of the HowToSFMC Scriptmas tradition where the team and the community share some of their top scripts, tips, hacks and workarounds.
Every day in the lead up to the big day, starting on Monday 12th December up until Christmas Eve, we’ll be revealing one scripted piece of goodness for you to grab and use in the new year!
On the First Day of Scriptmas, Ralph gave to me (us)...
A handy way to dynamically toggle campaign content so you can spend more time with family and let the Salesforce Elves handle the hard work!
Simply set your Start and End dates at the top of your CloudPage or Email...
Sprinkle a bit of Scriptmas magic around your campaign content...
And enjoy a bit of EggNog while the SF Elves are hard at work.
%%[
/* CALCULATE IF THE CAMPAIGN IS ACTIVE */
SET @Senddate = SystemDateToLocalDate(GetSendTime(FALSE))
SET @StartDate = DateParse("01/06/2022 00:00:00 AM")
SET @EndDate = DateParse("31/12/2022 11:00:00 PM")
SET @DateDiffStart = DateDiff(@StartDate, @Senddate ,"D")
SET @DateDiffEnd = DateDiff(@EndDate, @Senddate,"D")
IF @DateDiffStart >= 0 AND @DateDiffEnd <= 0 THEN
SET @CampaignPeriod = "TRUE"
ELSE
SET @CampaignPeriod = "FALSE"
ENDIF
]%%
/* Wrap your campaign content with the following */
%%[IF @CampaignPeriod == "true" THEN]%%
Insert campaign info here
%%[ENDIF]%%
Huge thank you to Ralph van den Broeck for the submission and helping us kick off another cheerful year of Scriptmas!
On the Second Day of Scriptmas, our good friend Lesley Higgins shared with us...
A creative way to display SFMC data on to CloudPages and External Websites by using JavaScript Code Resource pages.
With a dash of Sever-Side JavaScript and a pinch of Client-Side JavaScript, this script is as sweet as a candy cane!
<form>
<!-- Anchor for dynamically populated HTML -->
<div id="container"></div>
<!-- Submit Button -->
</form>
<!-- Load in SFMC Code Resource -->
<script type="text/javascript" src="https://cloud.<coderesource>.js"></script>
(function (/* root, doc */) {
<script runat="server">
Platform.Load("core","1.1.5");
var filter = {
Property: "Pricebook2Id",
SimpleOperator: "equals",
Value: "18DIGSF"
}
//Initiate Data Extension
var de = DataExtension.Init("Data-extension-external-key");
//Retrieve rows based on filter
var results = de.Rows.Retrieve(filter);
//Stringify and pass row data to AMPscript/Client-Side Javascript
var resultsString = Stringify(results);
Variable.SetValue("@results", resultsString);
</script>
var results = %%=v(@results)=%%;
for (var i = 0; i < results.length; i++) {
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = results[i].Web_Name;
checkbox.name = 'Sample';
checkbox.value = results[i].ProductCode;
var label = document.createElement('label')
label.htmlFor = results[i].Web_Name;
label.appendChild(document.createTextNode(results[i].Web_Name));
var br = document.createElement('br');
var Container = document.getElementById('container');
Container.appendChild(checkbox);
Container.appendChild(label);
Container.appendChild(br);
}
}(window, document));
Thanks for spreading the Scriptmas cheer Lesley!
Wanna hang out with Lesley? Give her a follow on Twitter!
On the Third Day of Scriptmas, Matt gifted us...
Some really handy SQL that automates a process that used to take the Salesforce Elves quite some time! The Elves are very fond of using Data Extensions to keep track of all the toys but they need to work in shifts.
Here's a nifty SQL script that picks up everyone from the DoubleChecked_NiceList
Data Extension that hasn't made their way to DoubleChecked_NiceList_processed
on the next run.
The Elves can even customize it a bit with additional WHERE clause criteria!
SELECT
s.PrimaryKey,
s.FirstName,
s.LastName,
s.EmailAddress
FROM [Source Data Extension] s
LEFT JOIN [Target Data Extension] t
ON s.PrimaryKey = t.PrimaryKey
WHERE
t.PrimaryKey IS NULL
I think it's safe to say that Matt Brulet is on the Salesforce Nice List this year for sharing this awesome SQL with us!
Matt can be found on LinkedIn and Twitter!
On the Fourth Day of Scriptmas, Robert shared with us...
An awesome bit of HTML and AMPscript that the Salesforce Elves use to send the Naughty and Nice List to Santa. With this in their workshop toolkit, they are able to build report tables in the time it takes them to sing our favorite holiday song All I Want for Christmas is an Automated Table
!
%%[
/*
OVERVIEW: build HTML tables dynamically based upon your client details. Create support tables to drive the table you want per the contact Account_Type
This allows the HTML tables to contain up to 10 columns
*/
/* code to determine Core/WFN/RS/CS */
set @lookupvalue = AttributeValue("Contact ID")
set @Account_Type = AttributeValue("Account Type")
set @Client_Type = AttributeValue("Client Type")
IF @Account_Type == 'ACC1' AND @Client_Type == 'Core1' THEN
set @email_BU = 'BU1'
set @HeaderTDStyle = ' style="text-align: center; vertical-align: center; background-color:#bb99ff; font-family: TaubSans,Arial,sans-serif; letter-spacing:0.2px;line-height:1em;font-size:12px;padding:6px;margin:0px;" '
ELSEIF @Account_Type == 'ACC2' AND @Client_Type == 'Core2' THEN
set @email_BU = 'BU2'
set @HeaderTDStyle = ' style="text-align: center; vertical-align: center; background-color:grey; font-family: TaubSans,Arial,sans-serif; letter-spacing:0.2px;line-height:1em;font-size:12px;padding:6px;margin:0px;" '
ELSEIF @Account_Type == 'ACC3' AND @Client_Type == 'Core3' THEN
set @email_BU = 'BU4'
set @HeaderTDStyle = ' style="text-align: center; vertical-align: center; background-color:blue; font-family: TaubSans,Arial,sans-serif; letter-spacing:0.2px;line-height:1em;font-size:12px;padding:6px;margin:0px;" '
ELSE
set @email_BU = 'Missing'
ENDIF
/* ================================== */
/* enter the email title here */
set @email_title = "test"
set @email_BU = "CS"
/* enter the email title here */
/* ================================== */
/* COMMENTS */
/*
HEADERS:
Header data stored, one row per header column
fetch data for header text and sort columns
hide column feature if needed
DATA:
Raw data stored in typical row/column
Fetch data dependent upon where header data is found and pull in by column order
*/
var @i, @HeaderRows, @HeaderRows, @HeaderRowCount
var @rows, @row, @contact_id, @prevcontact_id, @numRowsToReturn, @company_code, @deferral_amount, @prior_company_code
set @numRowsToReturn = 0
/* write the CSS styles here */
set @HeaderTRStyle = ' style="color:#ffffff;background-color:#7967AE; line-height:1em;padding:6px;" '
set @HeaderTRStyle = ' style="background-color: #ffffff;color:#000000;text-align:center;" '
set @TRStyleOdd = ' style="background-color: #ffffff;color:#000000;text-align:center;" '
set @TRStyleEven = ' style="background-color: #f2f2f2;color:#000000;text-align:center;" '
set @TDStyleOdd = ' style="background-color: #ffffff;color:#000000; text-align: center; vertical-align: center; font-family: TaubSans,Arial,sans-serif; letter-spacing:0.2px;line-height:1em;font-size:12px;padding:6px; word-wrap: break-word;margin:0px;" '
set @TDStyleEven = ' style="background-color: #f2f2f2;color:#000000; text-align: center; vertical-align: center; font-family: TaubSans,Arial,sans-serif; letter-spacing:0.2px;line-height:1em;font-size:12px;padding:6px; word-wrap: break-word;margin:0px;" '
set @HeaderRows = LookupOrderedRows("test_table_headers2", 0, "col_sort_num asc", "email_title", @email_title, "email_title_sub", @email_BU)
set @HeaderRowCount = rowcount(@HeaderRows)
/* Start Header Row If */
if @HeaderRowCount > 0 then
for @i = 1 to @HeaderRowCount DO
set @HeaderRow = row(@HeaderRows, @i)
set @col_title = trim(field(@HeaderRow,"col_title"))
set @col_sort_num = trim(field(@HeaderRow,"col_sort_num"))
set @col_hide = trim(field(@HeaderRow,"col_hide"))
/* create column headers in this block of code */
if @i == 1 and @col_title != "" and @col_hide == "" then
set @Hcol_disp1 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol1 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 2 and @col_title != "" and @col_hide == "" then
set @Hcol_disp2 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol2 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 3 and @col_title != "" and @col_hide == "" then
set @Hcol_disp3 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol3 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 4 and @col_title != "" and @col_hide == "" then
set @Hcol_disp4 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol4 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 5 and @col_title != "" and @col_hide == "" then
set @Hcol_disp5 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol5 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 6 and @col_title != "" and @col_hide == "" then
set @Hcol_disp6 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol6 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 7 and @col_title != "" and @col_hide == "" then
set @Hcol_disp7 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol7 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 8 and @col_title != "" and @col_hide == "" then
set @Hcol_disp8 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol8 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 9 and @col_title != "" and @col_hide == "" then
set @Hcol_disp9 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol9 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
elseif @i == 10 and @col_title != "" and @col_hide == "" then
set @Hcol_disp10 = concat('<th', @HeaderTDStyle, '>', @col_title, '</th>')
set @Hcol10 = concat("col", trim(field(@HeaderRow,"col_sort_num")))
endif
next @i
/* create the HTML table */
output(concat("<table style='border: 1px solid #000000;border-collapse: collapse; margin: 0 auto; padding: 0px; table-layout: fixed; width: 100%;'>"))
]%%
<!--
[if mso]>
<tr>
<td style="height:0.1pt">
</td>
</tr>
<![endif]
-->
%%[
/* write the TR(row) */
output(concat('<tr ', @HeaderTRStyle, ' >'))
/* write the TH(column headers) */
output(concat(v(@Hcol_disp1),v(@Hcol_disp2) ,v(@Hcol_disp3) ,v(@Hcol_disp4) ,v(@Hcol_disp5) ,v(@Hcol_disp6) ,v(@Hcol_disp7) ,v(@Hcol_disp8) ,v(@Hcol_disp9) ,v(@Hcol_disp10) ))
/* close the HTML row */
output(concat("</tr>"))
/* lookupOrderedRows("data extension name", number of rows to return, sort columns, WHERE criteria 1, WHERE criteria 1 value, WHERE criteria 2, WHERE criteria 2 value, etc...) */
set @Rows = LookupOrderedRows("test_table_list", 0, "data1, data2", "email_title", @email_title, "email_title_sub", @email_BU, "Contact Id", "0031P00001Eny4HQAR")
set @RowCount = rowcount(@Rows)
/* Start Row Display If */
if @RowCount > 0 then
for @i = 1 to @RowCount DO
/* create the rows/columns of data here */
set @Row = row(@Rows, @i)
set @vcol1 = ""
set @vcol2 = ""
set @vcol3 = ""
set @vcol4 = ""
set @vcol5 = ""
set @vcol6 = ""
set @vcol7 = ""
set @vcol8 = ""
set @vcol9 = ""
set @vcol10 = ""
/* set style for odd/even rows */
IF mod(@i,2) == 0 THEN
output(concat('<tr ', @TRStyleEven, ' >'))
set @TDStyle = @TDStyleEven
ELSE
output(concat('<tr ', @TRStyleOdd, ' >'))
set @TDStyle = @TDStyleOdd
ENDIF
output(concat('<tr ', @TRStyle, ' >'))
if length(@Hcol1) > 1 then
set @vcol1 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol1)), '</td>')
endif
if length(@Hcol2) > 1 then
set @vcol2 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol2)), '</td>')
endif
if length(@Hcol3) > 1 then
set @vcol3 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol3)), '</td>')
endif
if length(@Hcol4) > 1 then
set @vcol4 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol4)), '</td>')
endif
if length(@Hcol5) > 1 then
set @vcol5 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol5)), '</td>')
endif
if length(@Hcol6) > 1 then
set @vcol6 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol6)), '</td>')
endif
if length(@Hcol7) > 1 then
set @vcol7 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol7)), '</td>')
endif
if length(@Hcol8) > 1 then
set @vcol8 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol8)), '</td>')
endif
if length(@Hcol9) > 1 then
set @vcol9 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol9)), '</td>')
endif
if length(@Hcol10) > 1 then
set @vcol10 = concat('<td', @TDStyle, '>', trim(field(@Row,@Hcol10)), '</td>')
endif
output(concat(@vcol1, @vcol2, @vcol3, @vcol4, @vcol5, @vcol6, @vcol7, @vcol8, @vcol9, @vcol10))
output(concat("</tr>"))
next @i
/* End Row Display If 8?
endif
/* End Header Row If *?
endif
output(concat("</table>"))
output(concat("<!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->"))
]%%
</td>
</tr>
</table>
Thank you for sharing this awesome script with us Robert Forrester!
Robert can be found on LinkedIn!
On the Fifth Day of Scriptmas, Jake sent us...
Some SQL and AMPscript that the Salesforce Elves really wish they had before this Holiday season!
The Elves Data Extensions are filled with records of Salesforce wishes and gifts by all the good Trailblazers. This set of SQL and AMPscript would have helped them combine each Trailblazers many wishes into one email for each to send to Santa!
This way Santa wouldn't get so many emails and it would be easier for him to make sure all Trailblazer wishes are coming true!
It's not only great for Trailblazer wishes, but e-commerce wishlists, product refills, and many other use-cases!
This data will include more than 1 row per Subscriber
Let's call this the "todays_total_purchase_reminder_data" Data Extension
SELECT DISTINCT
SubscriberKey,
refill_id,
refill_name,
dosage,
next_purchase_reminder_date
FROM
purchases
WHERE
next_purchase_reminder_date > DATEADD(DAY, -1, GETDATE());
Let's call this "todays_total_purchase_reminder_data_GROUPED" Data Extension
SELECT
SubscriberKey
FROM
Refill_Overdue
GROUP BY
SubscriberKey
Now you will have a send list with only SubscriberKey and will only have 1 unique row for each Subscriber.
The next step will be creating an email that can perform a lookup function on the "todays_total_purchase_reminder_data" DE to get the data to display info on 1 or more records for the single email send.
%%[
/* 3rd Step Define AmpScript */
SET @SubscriberKey = [SubscriberKey]
/* Perform lookup on the Data Extension we populate with our 1st query */
SET @rows = LookupRows("todays_total_purchase_reminder_data",
"SubscriberKey",
@SubscriberKey)
SET @rowCount = rowcount(@rows)
/*
If you need each separate row from the 1st DE to be presented in the email via separate blocks of content, then follow instructions similar to https://ampscript.guide/lookuprows/ where the FOR loop loops through each row with a new block of html
If you want to build 1 sentence that separates each row of data in plain English with commas, then follow this BONUS Scriptmas code!
*/
/*
Get a string of refill Names combined...
original source: https://salesforce.stackexchange.com/questions/79214/how-to-create-loop-for-subject-line-using-ampscript
*/
IF @rowCount > 0 THEN
FOR @i = 1 TO @rowCount DO
SET @row = row(@rows, @i)
SET @refill_name = ProperCase(field(@row, "refill_name"))
IF NOT EMPTY(@refill_name_loop) THEN
IF @i == @rowCount AND @i > 1 THEN
SET @refill_name_final = CONCAT(@refill_name_loop, " and ", @refill_name)
ELSE
SET @refill_name = CONCAT(@refill_name_loop, ", ", @refill_name)
SET @refill_name_final = CONCAT(@refill_name_loop, ", ", @refill_name)
ENDIF
ELSE
SET @refill_name_final = @refill_name
ENDIF
SET @refill_name_loop = @refill_name
next @i
ENDIF
]%%
<!-- @refill_name_final will return simply 1 refill name with 0 commas if there's only 1 refill row for a Subscriber in the 1st DE
@refill_name_final will return a string similar to "refill1 and refill2" when the Subscriber has 2 refill rows in the 1st DE
@refill_name_final will return a string similar to "refill1, refill2, refill3, and refill4" for a Subscriber that has more than 2 refill rows -->
<p>You are due to refill the following items %%=v(@refill_name_final)=%%</p>
Thanks for the awesome code Jake Wiesenthal!
Jake can be found on LinkedIn.
On the Sixth day of Scriptmas Tim sent to us...
A CloudPage SSJS script that helps us generate SQL! As you can imagine, the Elves have a LOT of queries to run and a LOT of Data Extension fields to include. With this script they can automate building their queries!
<script language="javascript" runat="server">
Platform.Load("core","1");
var custKey = 'DEKeyGoesHere';
var DEName = '[DENameGoesHere]';
var alias = 'b'; /* Alias of choice goes here */
var myDE = DataExtension.Init(custKey);
var myFields = myDE.Fields.Retrieve();
var itemsToSelect = 'SELECT ';
for (i = 0; i < myFields.length; i++) {
if(i===0) {
if(alias) {
itemsToSelect += alias + '.[' + myFields[myFields[i].Ordinal].Name + ']<br>';
}
else{
itemsToSelect += '[' + myFields[myFields[i].Ordinal].Name + ']<br>';
}
}
else {
if(alias) {
itemsToSelect += ', ' + alias + '.[' + myFields[myFields[i].Ordinal].Name + ']<br>';
}
else{
itemsToSelect += ', [' + myFields[myFields[i].Ordinal].Name+ ']<br>';
}
}
}
itemsToSelect += 'FROM <br>' + DEName + ' ' + alias;
Write(itemsToSelect);
</script>
Big Scriptmas thank you to Tim Felch for sharing this great script!
Tim can be found on LinkedIn!
On the Seventh Day of Scriptmas, Elliott gave to us...
A SQL script helps the Salesforce Elves create a pivot table to make sure that everyone on Santa's Nice List has been good little Trailblazers that have been opening their Holiday Emails in the last 90 days!
SELECT A.[Subscriberkey],'Open' as 'StatType',
[EventDate] as 'DateOccured', [isunique] as 'unique', B.[Emailname], A.[JobID]
FROM _Open A
LEFT JOIN _Job B
ON A.[JobID] = B.[JobID]
WHERE [Eventdate] > dateadd(day, -90, GETUTCDATE())
UNION
SELECT [Subscriberkey],'Send' as 'StatType', [EventDate] as 'DateOccured',
'True' as 'unique', B.[Emailname], A.[JobID]
FROM _Sent_DV
LEFT JOIN _Job B
ON A.[JobID] = B.[JobID]
WHERE [Eventdate] > dateadd(day, -90, GETUTCDATE())
UNION
SELECT [Subscriberkey], 'Click' as 'StatType', [EventDate] as 'DateOccured',
[isunique] as 'unique', B.[Emailname], A.[JobID]
FROM _Click A
LEFT JOIN _Job B
ON A.[JobID] = B.[JobID]
WHERE [Eventdate] > dateadd(day, -90, GETUTCDATE()) AND [Linkname] <> 'Unsub'
UNION
SELECT [Subscriberkey],'Bounce' as 'StatType', [EventDate] as 'DateOccured',
'True' as 'unique', B.[Emailname], A.[JobID]
FROM _Bounce A
LEFT JOIN _Job B
ON A.[JobID] = B.[JobID]
WHERE [Eventdate] > dateadd(day, -90, GETUTCDATE())
Thanks Elliott Davidson, for this very handy script!
Elliott can be found on Instagram: @Ell_Dingo.
On the Eighth Day of Scriptmas, Cenk gave to us...
A super cool SSJS script that has the Salesforce Elves jumping for joy! While in the holiday rush, you can imagine all of the Elves working as hard as they can to get the Naughty and Nice lists squared away for Santa! Try as they might, sometimes those EmailAddress fields get named emailAddress
, Email
, emailAddr
, or any number of different things.
At the end of the year Papa Elf asks the Data Squad to do an audit of Data Extensions so they can do a post-holiday audit and clean up!
This script is exactly what they asked for this Scriptmas!
<script runat="server">
Platform.Load("core", "1");
var sfmc = new Script.Util.WSProxy();
try {
var request = sfmc.retrieve("DataExtension", [ "Name", "CustomerKey", "CategoryID", "IsSendable"], {
Property: "CustomerKey",
SimpleOperator: "isNotNull",
Value: " "
});
var de_email = [];
var all_de = request.Results;
for (var k in all_de) {
var fields = sfmc.retrieve("DataExtensionField", [
"FieldType",
"Name"
], {
Property: "DataExtension.CustomerKey",
SimpleOperator: "equals",
Value: all_de[k].CustomerKey
});
for (var f in fields.Results) {
if(fields.Results[f].FieldType == 'EmailAddress' && !fields.Results[f].Name.indexOf(':') && (!all_de[k].CustomerKey.indexOf('_Salesforce') &&!all_de[k].Name.indexOf('_Salesforce') ) ){
de_email.push({
DEName: all_de[k].Name,
DEKey: all_de[k].CustomerKey,
DEField: fields.Results[f].Name
});
}
}
}
var email_de = de_email.join(",");
Write(Stringify(de_email));
} catch(error) {
Write(error);
}
</script>
Passing along the Data Squads thanks Cenk Imren!
If you want to send your thanks as well, Cenk can be found on LinkedIn and his website!
On the Ninth Day of Scriptmas, Elise gave to us...
A bit of Zodiac fun stitched together with some AMPscript! The Salesforce Elves fancy themselves astrologers and star gazers, with the AMPscript below, they will never have to guess what the current Zodiac sign is!
%%[
var @pattern, @date, @month, @day, @zodiacSign
SET @pattern = "^0*(\d+)$"
SET @date = Now()
SET @month = FormatNumber(RegExMatch(datePart(@date, "M"), @pattern, 1),"G")
SET @day = FormatNumber(RegExMatch(datePart(@date, "D"), @pattern, 1),"G")
IF @month == 1 THEN
IF @day <= 19 THEN
SET @zodiacSign = 'Capricorn'
ELSEIF @day > 19 THEN
SET @zodiacSign = 'Aquarius'
ENDIF
ENDIF
IF @month == 2 THEN
IF @day <= 18 THEN
SET @zodiacSign = 'Aquarius'
ELSEIF @day > 18 THEN
SET @zodiacSign = 'Pisces'
ENDIF
ENDIF
IF @month == 3 THEN
IF @day <= 20 THEN
SET @zodiacSign = 'Pisces' THEN
ELSEIF @day > 20 THEN
SET @zodiacSign = 'Aries'
ENDIF
ENDIF
IF @month == 4 THEN
IF @day <= 19 THEN
SET @zodiacSign = 'Aries' THEN
ELSEIF @day > 19 THEN
SET @zodiacSign = 'Taurus'
ENDIF
ENDIF
IF @month == 5 THEN
IF @day <= 20 THEN
SET @zodiacSign = 'Taurus' THEN
ELSEIF @day > 20 THEN
SET @zodiacSign = 'Gemini'
ENDIF
ENDIF
IF @month == 6 THEN
IF @day <= 20 THEN
SET @zodiacSign = 'Gemini' THEN
ELSEIF @day > 20 THEN
SET @zodiacSign = 'Cancer'
ENDIF
ENDIF
IF @month == 7 THEN
IF @day <= 22 THEN
SET @zodiacSign = 'Cancer' THEN
ELSEIF @day > 22 THEN
SET @zodiacSign = 'Leo'
ENDIF
ENDIF
IF @month == 8 THEN
IF @day <= 22 THEN
SET @zodiacSign = 'Leo' THEN
ELSEIF @day > 22 THEN
SET @zodiacSign = 'Virgo'
ENDIF
ENDIF
IF @month == 9 THEN
IF @day <= 22 THEN
SET @zodiacSign = 'Virgo' THEN
ELSEIF @day > 22 THEN
SET @zodiacSign = 'Libra'
ENDIF
ENDIF
IF @month == 10 THEN
IF @day <= 22 THEN
SET @zodiacSign = 'Libra' THEN
ELSEIF @day > 22 THEN
SET @zodiacSign = 'Scorpio'
ENDIF
ENDIF
IF @month == 11 THEN
IF @day <= 21 THEN
SET @zodiacSign = 'Scorpio' THEN
ELSEIF @day > 21 THEN
SET @zodiacSign = 'Sagittarius'
ENDIF
ENDIF
IF @month == 12 THEN
IF @day <= 21 THEN
SET @zodiacSign = 'Sagittarius' THEN
ELSEIF @day > 21 THEN
SET @zodiacSign = 'Capricorn'
ENDIF
ENDIF
]%%
Thanks for this great AMPscript Elise Carlson.
Elise can found over on LinkedIn!
On the Tenth day of Scriptmas, Akash gave to us!
A very helpful SQL timesaver for the Salesforce Elves! Thanks to just a small change in how they were writing their SQL case statements, the can simplify their script and be less repetitive!
Instead of using this:
SELECT
CASE
WHEN Region = ‘North’ THEN ‘Brand A’
WHEN Region = ‘South’ THEN ‘Brand B’
ELSE ‘Brand C’
END AS Brand
FROM dataExtention
We can use this:
SELECT
Brand = CASE Region
WHEN ‘North’ THEN ‘Brand A’
WHEN ‘South’ THEN ‘Brand B’
ELSE ‘Brand C’
END
FROM dataExtention
Thanks for this timesaving adjustment Akash Israni!
Akash can be found on LinkdIn and Twitter.
On the Eleventh day of Scriptmas, Corrina shared with us...
Some extremely helpful AMPscript that the Salesforce Elves have been using all holiday season! With the AMPscript below, the Elves are able to set up a handy dynamic Sender Profile so they can control how their emails are being sent out of SFMC and personalize how they are being seen in the inbox!
%%[ var @customerId, @AccountId, @SubId, @SubName, @customerId, @AccountId, @ManagerId, @ManagerName
set @customerId = [_subscriberKey]
set @AccountId = Lookup("Contact_Salesforce","AccountId","_ContactKey", @customerId)
set @SubId = Lookup("Account_Salesforce","Advisor__c","Id", @AccountId)
set @FromName = Lookup("User_Salesforce","Name","Id", @SubId)
set @ManagerId = Lookup("Account_Salesforce","Manager__c","Id", @AccountId)
set @ManagerEmail = Lookup("User_Salesforce","Email","Id", @ManagerId)]%%
%%=v(@FromName)=%%
%%=v(@ManagerEmail)=%%
Thanks for this awesome AMPscript Corina Cohen!
Corrina can be found on LinkedIn.
On the Twelfth day of Scriptmas, Cameron gave to us...
A nifty little solution to see which of your Salesforce Elves is working hard this festive season! With the SSJS below, Scriptmas Santa can quickly see which Elves are on the working hard list and which are taking a little Scriptmas break of their own!
<script runat="server">
Platform.Load("Core","1");
try {
var prox = new Script.Util.WSProxy();
var cols = ["Name","CustomerKey","NotificationEmailAddress", "UserID", "ActiveFlag", "Email", "IsAPIUser", "AccountUserID", "LastSuccessfulLogin", "CreatedDate", "Roles"];
var filter = {
LeftOperand: {Property: "Email",SimpleOperator: "like",Value: "@"},
LogicalOperator: "AND",
RightOperand: {Property: "ActiveFlag",SimpleOperator: "equals",Value: "true"}
};
var res = prox.retrieve("AccountUser", cols, filter);
Write(Stringify(res.Results)+"<br><br><br>");
Write("<table border=1><tr><th>Name</th><th>Email</th><th>CreatedDate</th><th>LastSuccessfulLogin</th><th>Roles</th></tr>");
for (i = 0; i < res.Results.length; i++) {
Write("<tr><td>" + res.Results[i].Name + "</td><td>" + res.Results[i].Email + "</td><td>" + res.Results[i].CreatedDate + "</td><td>" + res.Results[i].LastSuccessfulLogin + "</td><td>");
for (r = 0; r < res.Results[i].Roles.length; r++) {
Write(res.Results[i].Roles[r].Name + "<br>");
}
Write("</td></tr>");
}
Write("</table>");
}
catch(error) {
Write('Message: ' + error);
}
</script>
Passing holiday cheer to Cam Robert for this gift!
Send Cam a thank you note on LinkedIn or through his website!
Discovered under the wrapping paper strewn on our desks, from Corrina Cohen, a magical hack* to delight our Salesforce Elves!
Busy Elves love to multitask and this script does just that. But be sure to store your Client ID and Secret Key outside the activity to keep it safe.
*Undocumented and Unsupported RESTProxy Magic within!
//NOTE1: Store as a code resource if you arre going to include your client id and secret
//NOTE2: It is alreay in a Try/Catch for testing if you want to remove it to simplify the file
<script runat="server">
var api = new Script.Util.RestProxy("Client Id", "Client Secret");
try{
var jbdate = {
"ContactKey": "",
"EventDefinitionKey":"JOURNEY BUILDER API EVENT KEY",
"Data": {
"subscriberkey":"",
"email":"",
"firstname":"",
"lastname":"",
"ANY OTHER FIELDS YOU WANT POPULATED":""
}
};
var res1 = api.Post("/interaction/v1/events", jbdate);
Platform.Response.Write(Platform.Function.Stringify(res1));
} catch(e1)
{Platform.Response.Write(Platform.Function.Stringify(e1));}
</script>
Pass holiday cheer to Corrina Cohen for showing this magic at LinkedIn!