Skip to content

Instantly share code, notes, and snippets.

View katydorjee's full-sized avatar
🤩

Karma Tsering Dorjee katydorjee

🤩
View GitHub Profile
@katydorjee
katydorjee / Print SSJS variable in HTML using GTL.html
Last active November 13, 2023 19:54
Print SSJS variable in HTML using GTL
<script runat="server">
Platform.Load("Core","1.1.1");
var customerName = "Dorjee";
</script>
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
@katydorjee
katydorjee / SQL Query Email address pattern check.sql
Created November 13, 2023 09:44
SQL Query Email address pattern check
SELECT ID, FirstName, LastName, EmailAddress FROM CustomerMaster
WHERE EmailAddress NOT LIKE '%_@__%.__%'
@katydorjee
katydorjee / Upsert (add or update) Publication list.js
Created November 8, 2023 00:17
Upsert (add or update) Publication list
updatePublicationList(12345, "003X123456789", "Unsubscribed")
function updatePublicationList(listId, subscriberKey, status) {
/*
status = Unsubscribed or status = Active
*/
var subArr = {
"SubscriberKey": subscriberKey,
"Lists": []
};
@katydorjee
katydorjee / Clear Data Extension.js
Created October 27, 2023 06:03
Clear Data Extension
function clearDataExtension(externalKey)
{
var prox = new Script.Util.WSProxy();
var action = "ClearData";
var props = { CustomerKey: externalKey };
var data = prox.performItem("DataExtension", props, action);
}
@katydorjee
katydorjee / Bitly API to Shorten the URL in Ampscript.html
Created March 28, 2017 09:08
Bitly API to Shorten the URL in Ampscript
%%[
SET @query = "i love momo"
SET @URL = TRIM(HTTPGet(Concat("https://api-ssl.bitly.com/v3/shorten?access_token=<Access Token>&format=txt&longUrl=https%3A%2F%2Fwww.google.com/#q=",@query)))
]%%
%%=v(@URL)=%%
<!--
Note: You need to create Bitly account and get the 'Access Token'
https://bitly.com
@katydorjee
katydorjee / execute SQL query in SSJS.js
Created September 20, 2023 01:33
Execute SQL query in SSJS.js
<script runat="server">
Platform.Load("Core","1.1.1");
try {
var qd = QueryDefinition.Init("SQL_Query_External_Key");
var campaignId = 'WINTER SALE'
var sql = "SELECT SubscriberKey, EmailAddress, FirstName, Status FROM MasterCustomer WHERE Status = '" + campaignId + "' FROM CampaignMaster";
var status = qd.Update({
Name : "SQL_Query_Name",
@katydorjee
katydorjee / Delete a record from DataExtension using AMPscript.html
Last active September 20, 2023 01:26
Delete a record from DataExtension using AMPscript
%%[
SET @status = DeleteData("DataExtension Name", "SubscriberKey","XXXXXXXXXX")
]%%
Status: %%=v(@status)=%%
@katydorjee
katydorjee / Select SQL to return records modified in the last hour.sql
Created June 4, 2020 01:22
Select SQL to return records modified in the last hour
SELECT Id,
Email,
FirstName,
LastModifiedDate,
CurrentDateTime
FROM (
SELECT Id,
Email,
FirstName,
LastModifiedDate at time zone 'Central America Standard Time' at time zone 'Aus Eastern Standard Time' LastModifiedDate,
@katydorjee
katydorjee / Get Ramdom top 10 records from a table.sql
Created May 8, 2023 07:04
Get Ramdom top 10 records from a table
SELECT TOP 10 [Contact ID],
Email,
[Full Name],
[First Name],
[Last Name],
Mobile
FROM [Customer]
ORDER BY NEWID()
@katydorjee
katydorjee / Get Data Extension Total Row Count.js
Created August 8, 2023 01:53
Get Data Extension Total Row Count
function getDataExtensionRowCount(DE_Name) {
if (DE_Name == '' || DE_Name == null) {
return null;
} else {
var ampscriptCodeLine = '%' + '%[SET @dataExtensionRowCount = DataExtensionRowCount("' + DE_Name + '")]%' + '%';
Platform.Function.TreatAsContent(ampscriptCodeLine);
var dataExtensionRowCount = Platform.Variable.GetValue("@dataExtensionRowCount");
return DataExtensionRowCount(dataExtensionRowCount);
}
}