Skip to content

Instantly share code, notes, and snippets.

View katydorjee's full-sized avatar
🤩

Karma Tsering Dorjee katydorjee

🤩
View GitHub Profile
@katydorjee
katydorjee / sfmc-ampscript-lookup-single-column-single-row.amp
Created February 6, 2017 18:34 — forked from wvpv/sfmc-ampscript-lookup-single-column-single-row.amp
SFMC AMPScript Lookup value of single column value from a certain row
%%[
var @DEColumn1, @lookupValue
set @lookupValue = "whee"
set @DEColumn1 = Lookup("DataExtensionName", "ReturnColumn", "LookupColumn", @lookupValue)
]%%
DEColumn1 is %%=v(@DEColumn1)=%%
@katydorjee
katydorjee / API to delete subscriber in Server Side Javascript.html
Created March 28, 2017 09:04
API to delete subscriber in Server Side Javascript
<script runat="server">
Platform.Load('Core','1');
var username = 'Username';
var password = 'PaSsWoRd';
var serviceURL = 'https://webservice.s7.exacttarget.com/Service.asmx';
//DE contains all the subscribers to be deleted. Delete all subscribers where field value of IsDeletedFromAllsubscribers is False
var srcDE = DataExtension.Init("Data Extension External key");
var ds = srcDE.Rows.Retrieve({Property:"IsDeletedFromAllsubscribers",SimpleOperator:"equals",Value:"False"});
@katydorjee
katydorjee / Returns specified value from a Data Extension - Ampscript.html
Last active March 28, 2017 17:09
Returns specified value from a Data Extension - Ampscript
%%[
set @returnValue = Lookup("Data Extension name", "Field name fetch from the DE", "Field for matching condition", "Value for matching condition")
]%%
%%=v(@returnValue)=%%
<!--
This function will return only the first occurrence of the record in a DE
-->
@katydorjee
katydorjee / Lookup Rows from a Data Extension - Ampscript.html
Last active March 28, 2017 17:10
Lookup Rows from a Data Extension - Ampscript
%%[
SET @query = "Query text"
SET @resultSet = LookupRows("Data Extension name","Field name for matching condition", @query)
IF RowCount(@resultSet) > 0 THEN
SET @row = row(@resultSet,1)
SET @Field1 = Field(@row,"FieldName1")
SET @Field2 = Field(@row,"FieldName2")
SET @Field3 = Field(@row,"FieldName3")
ENDIF
]%%
@katydorjee
katydorjee / Get all Subscribers based on their status.sql
Created March 30, 2017 03:13
Get all Subscribers based on their status
-- Get all Active
SELECT sb.SubscriberKey, sb.EmailAddress, sb.Status, ea.[First Name], ea.[Last Name], ea.Gender, ea.[Date of Birth], ea.Address, ea.Suburb, ea.State, ea.Postcode, sb.DateJoined
FROM _Subscribers sb
LEFT JOIN _EnterpriseAttribute ea ON sb.SubscriberID=ea._SubscriberID
WHERE sb.Status = 'Active'
-- Get all Unsubscribe
SELECT sb.SubscriberKey, sb.EmailAddress, sb.Status, ea.[First Name], ea.[Last Name], ea.Gender, ea.[Date of Birth], ea.Address, ea.Suburb, ea.State, ea.Postcode, sb.DateJoined
FROM _Subscribers sb
@katydorjee
katydorjee / SMS Optout using API.js
Created October 27, 2017 03:24
SMS Optout using API
<script runat="server">
Platform.Load("core", "1");
var url = 'https://auth.exacttargetapis.com/v1/requestToken';
var contentType = 'application/json';
var payload = Stringify({
"clientId": "XXXXXXXXXXXXXXXXXXXXXXXXXX",
"clientSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXX"
});
var headerNames = ["Encoding"];
var headerValues = ["utf-8"];
@katydorjee
katydorjee / Debug AMPscript using Server-Side JavaScript (SSJS).html
Created June 5, 2017 18:18
Debug AMPscript using Server-Side JavaScript (SSJS)
<script runat=server>
Platform.Load("Core","1");
</script>
<script runat=server>
try{
</script>
%%[
SET @SKey = RequestParameter("skey")
@katydorjee
katydorjee / SFMC-AMPScript-Upsert-Data-Extension-Row
Created August 13, 2018 17:44
SFMC AMPScript to Insert/Update Data Extension Row (use this function only in landing pages and SMS messages)
%%[
VAR @SubscriberKey, @firstName, @lastName, @returnValue
SET @SubscriberKey = "123"
SET @firstName = "Karma"
SET @lastName = "Dorjee"
SET @returnValue = UpsertData("My_Test_DataExtension",1,"SubscriberKey",@SubscriberKey,"FirstName",@firstName,"LastName",@lastName)
]%%
No of affected rows : %%=v(@returnValue)=%%
@katydorjee
katydorjee / sfmc-deduplication-with-row-number-partition.sql
Created September 14, 2018 17:02 — forked from wvpv/sfmc-deduplication-with-row-number-partition.sql
sfmc-deduplication-with-row-number-partition.sql
select
x.emailaddress
, x.subscriberkey
from (
select
w.emailaddress
, w.subscriberkey
, w.insertDate
, row_number() over (partition by w.subscriberkey order by w.insertDate asc) ranking
from Welcome_Trigger w
@katydorjee
katydorjee / Clear-Data-Extension.sql
Created June 16, 2019 10:31
Clear Data Extension using SQL query
SELECT * FROM "Name_of_the_Data_Extension" WHERE 1 = 2
/*
Specify the DE name within a double quote.
*/