I know I am not the only one who has, despite best efforts to maintain a logical folder structure, not been able to find a Data Extension (DE). In fact, one of the most common frustrations in Marketing Cloud is the inability to search for a DE using out-of-the-box search functionality, which only searches the parent level, not child folders.
There are a few solutions to this, none of which are “just leave every DE in the parent folder so it’s easier to search.”
There is a Chrome extension by DESelect, which has worked for me on and off throughout the years. Alternatively, you can craft your own search form on a CloudPage.
But, what if you're practically living in Slack? Integrating a solution into your Slack workspace could significantly streamline your workflow. Enter the Slack Slash Command, a nifty tool for creating custom interactive commands. Here’s how to set it up:
Step 1: Create a Slack App
Begin by creating a Slack App. This app will house your custom slash command.
Step 2: Craft Your Slash Command
Navigate to your App Management dashboard, select your app, and find Slash Commands under Features. Click Create New Command and fill in the details:
Command: Choose a simple yet unique name to avoid clashes with existing commands. For instance, “/delookup.”
Request URL: Your command's endpoint that Slack will hit when the command is invoked. It should be HTTPS. This will be a Code Resource in Marketing Cloud.
Short Description: Summarize what your command does.
Usage Hint: Offer a hint or example usage to guide users.
The Importance of Naming
Slash commands aren't namespaced, meaning commands can overlap. If conflicts arise, Slack defaults to the most recently installed command. Pick a name that's both memorable and unique to your needs.
Step 3: Prepare for Incoming Commands
When someone uses your slash command, Slack sends a detailed HTTP POST request to your specified URL. For a command like “/delookup pets,” expect a payload similar to:
token=gIkuvaNzQIHg97ATvDxqgjtO
&team_id=T0001
&team_domain=example
&channel_id=C2147483705
&channel_name=lesley-slack-dev
&user_id=U2147483697
&user_name=lhiggins
&command=%2Fdelookup
&text=pets
&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FTDJ8J3TDM…
&trigger_id=13345224609.738474920.8088930838d88f008e0
&api_app_id=A123456
This data allows for validations and tailored responses based on user, domain, or channel specifics.
The Core Code
Slack limits the time to the first slash command response to 3 seconds, which can be a problem for longer tasks. DE lookups are relatively quick, though, and will almost always respond within the requirement.
I used “like” rather than “equals” as my simple operator because if you're the kind of person who forgot where they put their DE, you also probably forgot what you named it.
Here is the basic code, which exists on a JSON Code Resource in Marketing Cloud. It isolates the "text' parameter and loops through all results that match:
<script runat="server">
Platform.Load("core","1.1.5");
var post = Platform.Request.GetPostData();
var json = Platform.Function.ParseJSON(post);
var posttext = Platform.Request.GetFormField('text');
var DEprop = 'Name'; // We are searching by Name, but we could also search by External Key
var DEval = posttext; // Provide the value of the Name or External Key
var FindDE = DataExtension.Retrieve({Property:DEprop, SimpleOperator:"like", Value:DEval}); // Retrieve the DE based on the provided value
for (var i = 0; i < FindDE.length; i++) { // Loop through the results
var FolderID = FindDE[i].CategoryID; // Retrieve the folder ID for the DE
var DEname = FindDE[i].Name; // Retrieve the DE name
var list = [DEname]; // Initialize the list with the current DE name
var path = function(id) { // Recursive function to find the folder path
if (id > 0) {
var results = Folder.Retrieve({Property:"ID", SimpleOperator:"equals", Value:id}); // Retrieve the folder based on the ID
if (results && results.length > 0) {
list.unshift(results[0].Name); // Prepend the folder name to the list
return path(results[0].ParentFolder.ID); // Recursive call to find the parent folder
}
} else {
return id;
}
};
path(FolderID); // Begin recursion with the DE's folder ID
Write(list.join(" > ") + "\n"); // Output the DE name and folder path, separated by " > "
}
</script>
Results in Action
When I type in the command "/delookup subscriber" I receive the following results:
Invoking this Slash Command yields a clear, ephemeral response showing the DE and its folder path, providing quick access to the needed information without overwhelming the channel. By default, messages sent in response to Slack slash commands are set to ephemeral. Ephemeral messages do not persist across sessions, desktop and mobile apps, or reloads. Once the session is closed, ephemeral messages will disappear and cannot be recovered.
Comments