Skip to content

Instantly share code, notes, and snippets.

%%[
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)"}
]
@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>
SELECT DISTINCT
a.SubscriberKey
, a.EmailAddress
, j.JobID
, j.EmailName
, s.EventDate
, j.SendClassificationType
, j.SendType
, a.DateUnsubscribed
FROM _Subscribers a
%%[
/*
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));
}
@camrobert
camrobert / SSJS: WSProxy Simple
Created January 6, 2023 09:12
Code Snippet
<script runat="server">
Platform.Load("Core","1");
try {
var prox = new Script.Util.WSProxy();
var cols = ["Name","CustomerKey","CategoryID"];
var filter = {Property: "Name",SimpleOperator: "equals",Value: "Cam DE"};
var res = prox.retrieve("DataExtension",cols,filter);
//Write('Message: '+ Stringify(res));
for (s = 0; s < res.Results.length; s++) {
<script runat="server">
/*
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_httpPost.html
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/validateEmail.html
*/
Platform.Load("Core","1");
try {
/*=== (unsafe) Plain Text API Credentials ===*/
var authurl = "https://mcxxxxxxxxxxxxxxxx.auth.marketingcloudapis.com/";
@camrobert
camrobert / SSJS Get all Users
Created December 2, 2022 12:45
SSJS and WSProxy code to return all valid users in a Marketing Cloud instance
<script runat="server">
/*Code provided as is without warranty - make sure you understand what this code does before using it - use at your own risk*/
Platform.Load("Core","1");
try {
var prox = new Script.Util.WSProxy();
//================== https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/accountuser.html
var cols = ["Name","CustomerKey","NotificationEmailAddress", "UserID", "ActiveFlag", "Email", "IsAPIUser", "AccountUserID", "LastSuccessfulLogin", "CreatedDate", "Roles"];
//================= https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_WSProxy_basic_retrieve.html
var filter = {
LeftOperand: {Property: "Email",SimpleOperator: "like",Value: "@"},