Skip to content

Instantly share code, notes, and snippets.

View MyCueCards's full-sized avatar

Harley MyCueCards

View GitHub Profile
@MyCueCards
MyCueCards / Update_DataExtract.ssjs
Last active November 10, 2024 00:17
In Salesforce Marketing Cloud Engagement (aka SFMC or MCE), run the below as a script activity in automation studio. The activity is meant to update file names within the data extract activity.
/* ************************************************************************
Unable to find specific documentation for the endpoint. Listing these references instead:
Supported Operations for Objects and Methods (SOAP API)
https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/supported_operations_for_objects_and_methods.html
DataExtractActivity (SOAP API Object)
https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/dataextractactivity.html
Create via WSProxy (giving similar endpoint, but for POST)
@MyCueCards
MyCueCards / MCP_ExternalEmailCampaignEventsETL
Created July 5, 2024 19:45
Query to gather records for External Email Campaign Events ETL
/* ************************************
- Salesforce Marketing Cloud Personalization (formerly Interaction Studio, formerly Evergage)
- External Email Campaign Events ETL
- https://help.salesforce.com/s/articleView?id=sf.mc_pers_etl_external_email_campaign_events_data_feed.htm&type=5
************************************ */
SELECT
sub.emailAddress AS [attribute:emailAddress],
s.SubscriberID AS [attribute:sfmcSubscriberID],
j.EmailID AS [externalCampaignId],
@MyCueCards
MyCueCards / CloudPageURL-Parameters
Created April 27, 2024 15:41
For instances where the parameter is not generating correctly, add CONCAT and SUBSTRING to alter.
/*
One use, if your system snippet is directed to a custom cloud page, use the below instead
of [%%=RedirectTo(CloudPagesURL(##))=%%]. Without, there may be an error when using
parameter manager. This will avoid generating two question marks in the URL.
*/
%%=RedirectTo(Concat(CloudPagesURL(##),SUBSTRING('?',1,0)))=%%
@MyCueCards
MyCueCards / Content-Security-Policy header.ssjs
Created July 28, 2023 15:41
Content-Security-Policy (CSP) header examples for Salesforce Marketing Cloud CloudPages.
// SFMC source doc: https://help.salesforce.com/s/articleView?id=sf.mc_cp_cloud_pages_security_best_practices.htm&type=5
// CSP page for other examples: https://content-security-policy.com/
// standard example from doc
<script runat=server>
Platform.Response.SetResponseHeader("Strict-Transport-Security","max-age=200");
Platform.Response.SetResponseHeader("X-XSS-Protection","1; mode=block");
Platform.Response.SetResponseHeader("X-Frame-Options","Deny");
Platform.Response.SetResponseHeader("X-Content-Type-Options","nosniff");
Platform.Response.SetResponseHeader("Referrer-Policy","strict-origin-when-cross-origin");
@MyCueCards
MyCueCards / createdManyDeWithSsjs.ssjs
Created July 18, 2023 23:57
Populate with ampscript then run with ssjs activity. Create many data extensions with SSJS and ampscript
// populate with ampscript
%%[
/* Replace 'thisIsTheSourceDe' with the actual name of your data extension */
var @dataExtensionName
set @dataExtensionName = "thisIsTheSourceDe"
/* Replace 'myCustomerKey' with the actual field name you want to populate */
var @fieldName
set @fieldName = "myCustomerKey"
@MyCueCards
MyCueCards / SSJS Add Fields.ssjs
Created July 18, 2023 05:08
Adds multiple fields to a DE using SSJS. Loops through a DE to get the customer key.
// Name AND customer key of DE are: thisIsTheSourceDe
// Field in the above DE is: myCustomerKey (text)
// https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_dataExtensionFieldsAdd.html
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
try {
@MyCueCards
MyCueCards / debugAmpscript.ssjs
Created August 22, 2022 00:36
Using SSJS to debug AMPscript. Will produce text to attempt to determine 500 error on CloudPage.
// Originally found: https://salesforce.stackexchange.com/questions/271607/createsalesforceobject-ampscript
<script runat="server">
Platform.Load("Core","1.1.1");
try{
</script>
%%[ YOUR AMPSCRIPT CODE ]%%
<script runat="server">
@MyCueCards
MyCueCards / SelectStateAndDisabled.ampscript
Created November 17, 2021 19:57
DE has states listed by postal abbr, but selection list does not. Pre-populate state in selection and disable selection list.
%%[
SET @finalState = deStateValue
]%%
<form id="SubmitRegistration" action="%%=CloudPagesURL('111')=%%" method="post">
<select class="inputBox state" id="" name="formState" title="State" %%=IIF(EMPTY(@finalState),'','disabled')=%%>
<option value="">--</option>
<option value="Alabama" %%=IIF(@finalState == 'AL','Selected','')=%%>Alabama</option>
<option value="Alaska" %%=IIF(@finalState == 'AK','Selected','')=%%>Alaska</option>
@MyCueCards
MyCueCards / UpdateCRMObject.ssjs
Created October 19, 2021 15:29
Update the Salesforce CRM Contact Object with SSJS. Looping through DE with SSJS.
<script runat="server">
Platform.Load("Core","1.1.1");
var records = DataExtension.Init("DeNameToGetValues");
var data = records.Rows.Retrieve({Property:"run",SimpleOperator:"equals",Value:1}); // DE should have a field called 'run' that is boolean to filter.
var datalength = data.length;
for (var i = 0 ; i < data.length ; i ++) {
var sf_fieldUpdateString = [];
sf_fieldUpdateString.push(data[i].SubscriberKey);
@MyCueCards
MyCueCards / AMPScript Encryption (Simple).html
Created August 9, 2021 16:51
Basic example of AMPScript SHA256() function, returning SHA256 hash tag based on the string value
%%[
SET @CheckForEmail = IsEmailAddress(_SubscriberKey)
IF @CheckForEmail == 'false' THEN
SET @FinalSubscriberKey = _SubscriberKey
ELSE
SET @FinalSubscriberKey = SHA256(_SubscriberKey,'UTF-16')
ENDIF
SET @Link = CONCAT('https://[DomainStuffHere]?mcsubkey=', @FinalSubscriberKey)