Skip to content

Instantly share code, notes, and snippets.

View wvpv's full-sized avatar

Adam Spriggs wvpv

View GitHub Profile
@wvpv
wvpv / sfmc-ampscript-one-click-unsubscribe.html
Last active November 18, 2025 14:50
One-Click Unsubscribe AMPscript
%%[
set @debug = 0
set @jid = AttributeValue("jobid")
set @listid = AttributeValue("listid")
set @batchid = AttributeValue("_JobSubscriberBatchID")
set @email = AttributeValue("emailaddr")
set @skey = AttributeValue("_subscriberkey")
set @reason = "One-Click Unsubscribe"
set @unsubscribeAll = RequestParameter("ua")
@wvpv
wvpv / sfmc-ampscript-truncate-decimal.amp
Last active September 30, 2025 22:01
SFMC-AMPscript-Truncate-Decimal
%%[
set @num1 = 12.99
set @num1_rounded = Format(@num1, "N0")
set @num1_formatted = @num1_rounded
if @num1_rounded > @num1 then
set @num1_formatted = subtract(@num1_rounded, 1)
endif
%%[
if _messagecontext == "PREVIEW" then
set @couponCode = "XX TEST XX"
else
/* include your sendable attribute/column here */
set @em = AttributeValue("emailAddr")
@wvpv
wvpv / SFMC-SSJS-retrieve-start-automation.js
Last active July 8, 2025 03:39
SFMC SSJS Retrieve and Start and Automation
<script runat="server">
Platform.Load("Core","1");
var automationCustomerKey = "CUSTOMERKEY-OF-AUTOMATION"
var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "Automation");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ProgramID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "CustomerKey");
@wvpv
wvpv / sfmc-ampscript-lookup-multiple-column-multiple-ordered-rows.amp
Last active July 8, 2025 03:38
SFMC AMScript Lookup multiple column values from multiple ordered rows
%%[
set @lookupValue = AttributeValue("lookupField") /* value from attribute or DE column in send context */
set @lookupValue = "whee" /* or a literal value */
set @numRowsToReturn = 0 /* 0 means all, max 2000 */
set @rows = LookupOrderedRows("DataExtensionName",@numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
@wvpv
wvpv / sfmc-ampscript-lookup-multiple-column-single-row.amp
Last active July 8, 2025 03:38
SFMC AMScript Lookup multiple column values from a single row
%%[
set @lookupValue = AttributeValue("lookupField") /* value from attribute or DE column in send context */
set @lookupValue = "whee" /* or a literal value */
set @rows = LookupRows("DataExtensionName","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
@wvpv
wvpv / sfmc-ampscript-lookup-single-column-single-row.amp
Last active July 8, 2025 03:37
SFMC AMPScript Lookup value of single column value from a certain row
%%[
set @lookupValue = AttributeValue("lookupField") /* value from attribute or DE column in send context */
set @lookupValue = "whoa" /* or a literal value */
set @DEColumn1 = Lookup("DataExtensionName", "DEColumn1", "LookupColumn", @lookupValue)
]%%
DEColumn1 is %%=v(@DEColumn1)=%%
@wvpv
wvpv / datatable-handler.js
Created June 13, 2025 00:19
DataTable AJAX Example - Handler
<script runat="server" language="javascript">
Platform.Load("core","1");
Platform.Response.SetResponseHeader("Connect","Keep-Alive");
Platform.Response.SetResponseHeader("Keep-Alive","timeout=40, max=200");
var page = Request.GetQueryStringParameter("page");
page = page ? page : 1;
var pageSize = Request.GetQueryStringParameter("pageSize");
pageSize = pageSize ? pageSize : 20;
@wvpv
wvpv / datatable.html
Created June 13, 2025 00:17
DataTable AJAX example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DataTable</title>
<link href="https://cdn.datatables.net/2.3.2/css/dataTables.dataTables.min.css" rel="stylesheet" integrity="sha384-gC2LYLqCExndkNE9hTLhmEXvk8ZgIf42nRengHFbC9uaws2Ho0TW+ENGe4w15AHy" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha384-NXgwF8Kv9SSAr+jemKKcbvQsz+teULH/a5UNJvZc6kP47hZgl62M1vGnw6gHQhb1" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/2.3.2/js/dataTables.min.js" integrity="sha384-RZEqG156bBQSxYY9lwjUz/nKVkqYj/QNK9dEjjyJ/EVTO7ndWwk6ZWEkvaKdRm/U" crossorigin="anonymous"></script>
<style>
@wvpv
wvpv / traverseChildFolders.js
Created March 12, 2025 18:33
Traverse Child Folders with SSJS
<script runat="server" language="javascript">
Platform.Load("core","1");
var prox = new Script.Util.WSProxy();
function traverseChildFolders(parentID) {
var cols = ["ID","ParentFolder.ID","Name"];
var filter = {Property: "ParentFolder.ID", SimpleOperator: "equals", Value: parentID};