Created
November 15, 2021 10:18
-
-
Save camrobert/c0f2838f641e341601b6d5eaf50aae1b to your computer and use it in GitHub Desktop.
SFMC DE Record Count Slack API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
======================================================= | |
Title: SFMC DE Record Count Slack API | |
Author: Cameron Robert | |
------------------------------------------------------- | |
Instructions: | |
1: Create a Javascript Code Resource CloudPage | |
2: Paste the below code to the page | |
3: Use the Cloud Page URL as "Request URL" for a "Slash Commands" component in the Slack API Dashboard. | |
4: Save and Authorise your Slack app to a workspace/channel. | |
5: Use the the Slash Command to interact, where any text immediatly after the inital Slash Command is the DE name. | |
For example: Using the slash command "/sfmcde" to find the row count of a DE called "My products DE" would be: "/sfmcde my products de" | |
======================================================= | |
*/ | |
<script runat="server"> | |
Platform.Load("Core","1"); | |
try { | |
var params = Platform.Request.GetFormField('text'); | |
var prox = new Script.Util.WSProxy(); | |
var cols = ["Name","CustomerKey","CategoryID","IsSendable"]; | |
var filter = {Property: "Name",SimpleOperator: "equals",Value: params}; | |
var desc = prox.retrieve("DataExtension", cols, filter); | |
if (desc.Results.length > 0) { | |
Platform.Variable.SetValue("@countde",params); | |
</script> | |
%%[SET @count = DataExtensionRowCount(@countde) | |
SET @response = Concat("Data Extension [" ,@countde, "] has " ,@count," records.") | |
]%% | |
<script runat="server"> | |
Write(Variable.GetValue("@response")); | |
} else { | |
Write("Error. Could not find a DE called ["+params+"]"); | |
} | |
} | |
catch(error) { | |
Write('Message: '+ error); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment