Skip to content

Instantly share code, notes, and snippets.

View katydorjee's full-sized avatar
🤩

Karma Tsering Dorjee katydorjee

🤩
View GitHub Profile
@katydorjee
katydorjee / Hide contents in Microsoft clients.html
Last active March 10, 2017 03:43
Hide contents in Microsoft clients
<!--[if !mso]><!-->
<div class="show" style="font-size: 0; max-height: 0; overflow: hidden; display: none;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="container">
<tbody>
<tr>
<td align="center" valign="top" bgcolor="#ffffff" style="display:none;" class="mobile-show">
<img src="http://placehold.it/600x80" width="600" height="80" style="display: block;" border="0" class="photo">
</td>
</tr>
</tbody>
@katydorjee
katydorjee / Server side javascript - DE LookupRows.js
Last active December 5, 2023 08:07
Server side javascript - DE LookupRows
<script runat="server">
Platform.Load("core","1");
var Lookup_value = 'apple';
var dataRows = Platform.Function.LookupRows('Data Extension name','Lookup field',Lookup_value);
if(dataRows && dataRows.length > 0) {
for(var i=0; i<dataRows.length; i++) {
Platform.Response.Write(dataRows[i]["Result_field_name"]);
}
}
@katydorjee
katydorjee / Server side javascript - Add Data to a Data Extension.html
Last active July 25, 2019 05:00
Server side javascript - Add Data to a Data Extension.html
<script runat="server">
Platform.Load("core","1");
var DE = DataExtension.Init('<Data Extension name>');
var AddRows = {
Field1: 'Value1',
Field2: 'Value2',
Field3: 'Value3'
};
var status = DE.Rows.Add(AddRows);
@katydorjee
katydorjee / Server Side Javascript - Retrieve Rows.js
Last active December 5, 2023 08:06
Server Side Javascript - Retrieve Rows
<script runat="server">
Platform.Load("core","1");
var targetDE = DataExtension.Init('DataExtension EXTERNAL KEY').Rows.Retrieve();
for (var i = 0; i < targetDE.length; i++)
{
Write(targetDE[i].Field1+'<br>');
Write(targetDE[i].Field2+'<br>');
Write(targetDE[i].Field3+'<br>');
}
@katydorjee
katydorjee / For loop in Ampscript.html
Created March 28, 2017 07:08
For loop in Ampscript
%%[
SET @pl = "a|b|c|d|e"
SET @prefArray = BuildRowSetFromString(@pl,"|")
SET @rCount = RowCount(@prefArray)
FOR @i = 1 TO @rCount DO
SET @ddd = Field(Row(@prefArray, @i),1)
]%%
%%=V(@ddd)=%% <br>
%%[
NEXT @i
@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 / 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 / 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