Skip to content

Instantly share code, notes, and snippets.

@camrobert
camrobert / Dad_Joke_CloudPage_SSJS.js
Created November 15, 2021 10:15
Dad Joke CloudPage SSJS code for Slack API Integration
/*
=======================================================
Title: Dad Joke CloudPage SSJS code for Slack API Integration.
Author: Cameron Robert
-------------------------------------------------------
Instructions:
1: Create a Javascript Code Resource CloudPage
2: Paste the below code to the page
3: Use the Cloud Page URL as "Request URL" for a "Slash Commands" component in the Slack API Dashboard.
4: Save and Authorise your Slack app to a workspace/channel, and use the Slash Command to interact
@camrobert
camrobert / DE_Count_Slack_API.sj
Created November 15, 2021 10:18
SFMC DE Record Count Slack API
/*
=======================================================
Title: SFMC DE Record Count Slack API
Author: Cameron Robert
-------------------------------------------------------
Instructions:
1: Create a Javascript Code Resource CloudPage
2: Paste the below code to the page
3: Use the Cloud Page URL as "Request URL" for a "Slash Commands" component in the Slack API Dashboard.
4: Save and Authorise your Slack app to a workspace/channel.
SELECT DISTINCT
a.SubscriberKey
, a.EmailAddress
, j.JobID
, j.EmailName
, s.EventDate
, j.SendClassificationType
, j.SendType
, a.DateUnsubscribed
FROM _Subscribers a
@camrobert
camrobert / BuildRowsetFromJson Documentation Sample
Created June 14, 2023 13:43
Recreate the BuildRowsetFromJson Documentation Usage Example
%%[
SET @json = '{"Flights": [{"Origin": "IND","Dest": "NYC","Price": 100.0},{"Origin": "IND","Dest": "LAX","Price": 200.0},{"Origin": "IND","Dest": "SEA","Price": 500.0,"PerBagSurcharge": 25}]}'
SET @rows = BuildRowsetFromJson(@json, '$.Flights[*]', 1)
]%%
<table border=1>
<tr><th>Origin</th><th>Dest</th><th>Price</th><th>PerBag Surcharge</th></tr>
%%[FOR @i = 1 TO Rowcount(@rows) DO]%%
<tr>
%%[FOR @c = 1 TO 4 DO]%%
<td>%%=Field(Row(@rows,@i),@c)=%%</td>
%%[
SET @fname = RequestParameter('fname')
SET @lname = RequestParameter('lname')
SET @email = RequestParameter('email')
IF NOT EMPTY(RequestParameter('pref1')) THEN
SET @Cats = "true"
ELSE
SET @Cats = "false"
ENDIF
%%[
SET @json = '{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateDoc(a)"},
{"value": "Open", "onclick": "OpenDoc(b)"},
{"value": "Save", "onclick": "SaveDoc(c)"}
]
%%[
/*
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/httppost2.html
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/access-token-s2s.html
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/validateEmail.html
*/
/*=== (Unsafe) Plain Text API Credentials ===*/
SET @client_id = "xxxxxxxxxxxxxxxxxx"
SET @client_secret = "xxxxxxxxxxxxxxxxxx"
%%[
SET @rows = LookupRows("DENAME", "Key", "Value")
FOR @i = 1 to RowCount(@rows) DO
]%%
EmailAddress: %%=Field(Row(@rows,i), 'EmailAddress')=%%<br>
%%[
NEXT @i
]%%
@camrobert
camrobert / SSJS: Baseplate
Created January 6, 2023 09:12
Code Snippet
<script runat="server">
Platform.Load("Core","1");
try {
//Do Functions Here
}
catch(error) {
Write('Message: '+ Stringify(error));
}