Skip to content

Instantly share code, notes, and snippets.

View MamaiRachid's full-sized avatar
🏠
Working from home

Rachid Mamai MamaiRachid

🏠
Working from home
  • Paris
View GitHub Profile
{
"startIndex": 0,
"itemsPerPage": 25,
"totalResults": 308,
"entry": [
{
"id": "dV9jX21YOHpNa0tzTGlYNXXXXXXXX",
"key": "AUTOMATION KEY",
"createdDate": "2020-01-16T14:53:53.177",
"name": "AUTOMATION NAME",
%%[
SET @MID = '50000XXXX'
SET @apiCreds = LOOKUP('REST_Credentials', 'apiCreds', 'MID', @MID)
SET @apiCreds = DecryptSymmetric(@apiCreds, 'aes', 'INT_PWD', @null, 'INT_SALT', @null, 'INT_IV', @null)
]%%
<script runat="server">
Platform.Load("Core","1.1.1");
@MamaiRachid
MamaiRachid / gist:88f6ab73be9131008f594c1d95c2d68f
Last active November 6, 2020 13:00
Code Snippet AMPScript code to unsubscribe a contact from Sales Cloud through a creation of a Task (Data Privacy app)
%%[ var @rows, @row, @rowCount, @subKey, @counter
set @rows = LookupRows("BRANDA_COMPLAINTS","OYBAccountID","50000XXXX","Secret", 1)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
for @counter = 1 to @rowCount do
set @row = row(@rows, @counter)
set @subKey = field(@row,"SubscriberKey")
set @created_taskId= CreateSalesforceObject('Task',3,'WhoId', @subKey, 'Subject', 'Datapm:Unsubscribe', 'Description', '{"channel":"email"}')
@MamaiRachid
MamaiRachid / ampscript_from_scriptactivity.js
Last active November 6, 2020 13:03
SSJS code to execute AMPScript from a Content block inside a Script activity in Automation Studio
<script runat="server">
var ampscriptCode = Platform.Function.ContentBlockByKey("YOUR_CONTENTBLOCK_KEY");
</script>
SELECT
comp.SubscriberKey,
comp.jobid,
eventdate,
emailname,
Domain,
ISNULL(comp.OYBAccountID,comp.AccountID) as OYBAccountID,
comp.AccountID
@MamaiRachid
MamaiRachid / gist:0bad2e10800c478bc69972e0dee6e377
Last active October 20, 2020 13:09
Unsubscribe from Newsletter by creating a Task on SalesCloud. SFMC - Data Privacy Manager
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Unsubscribe - Newsletter</title>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
@MamaiRachid
MamaiRachid / gist:95574a7cb6060993fcf2610e541b236f
Created October 20, 2020 12:48
Unsubscribe contact from newsletterEmailConsent on Sales Cloud by creating a Task
%%[
/* Check if the contact is subscribed to the newsletterEmail_Consent */
IF (@newsletterEmail_Consent != 'False') THEN
SET @timeNow = FormatDate(Now(),"iso")
SET @created_taskId= CreateSalesforceObject('Task',4,'WhoId', @subKey, 'Subject', 'Datapm:Unsubscribe', 'Description', '{"crCode":"100001"}', 'ActivityDate', @timeNow)
/* Update Consents Data Extension */
UpsertData("Consents", 1, "SubscriberKey", @subKey, "NewsletterEmail_Consent", "False")
ENDIF
]%%
@MamaiRachid
MamaiRachid / gist:bfa3e62e9760d60f4bdab9074c780df4
Created October 20, 2020 12:42
Get contact's consent from data extension
%%[
SET @emailaddr = AttributeValue("emailaddr")
SET @subKey = AttributeValue("_subscriberkey")
/* Get the NewsletterEmail_Consent value from Consents Data Extension */
SET @rowsConsents = LookupRows("Consents", "SubscriberKey", @subKey)
IF RowCount(@rowsConsents) > 0 then
SET @consentRow = Row(@rowsConsents,1)
SET @newsletterEmail_Consent = Field(@consentRow, "NewsletterEmail_Consent")
SELECT
CT.Id AS SubscriberKey,
CASE
WHEN CT.datapm__CommunicationRules__c LIKE '%100001%' THEN 'TRUE'
ELSE 'FALSE'
END AS NewsletterEmail_Consent,
CASE
%%=ContentBlockbyKey("4bd9cced-f9c5-49fe-927a-xxxxxxx")=%%