verified
Retrieve a DataExtension folder's pathLearn how to retreive a Folder's path in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy and Core methods.
Core
var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";
var de = DataExtension.Retrieve({
Property: "CustomerKey",
SimpleOperator: "equals",
Value: customerKey
});
var categoryId = de[0].CategoryID;
var name = de[0].Name;
var list = [];
list.push(name);
var path = function (id) {
if (id > 0) {
var results = Folder.Retrieve({
Property: "ID",
SimpleOperator: "equals",
Value: id
});
list.push(results[0].Name);
list = list.reverse();
return path(results[0].ParentFolder.ID);
} else {
return id;
}
};
path(categoryId);
var result = list.join(" / ");
<script runat="server">
Platform.Load("core", "1");
try {
var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";
var de = DataExtension.Retrieve({
Property: "CustomerKey",
SimpleOperator: "equals",
Value: customerKey
});
var categoryId = de[0].CategoryID;
var name = de[0].Name;
var list = [];
list.push(name);
var path = function (id) {
if (id > 0) {
var results = Folder.Retrieve({
Property: "ID",
SimpleOperator: "equals",
Value: id
});
list.push(results[0].Name);
list = list.reverse();
return path(results[0].ParentFolder.ID);
} else {
return id;
}
};
path(categoryId);
var result = list.join(" / ");
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
"Data Extensions / MyFolder / MySubFolder"
WSProxy
var api = new Script.Util.WSProxy();
var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";
var req = api.retrieve("DataExtension", ["Name", "CategoryID"], {
Property: "CustomerKey",
SimpleOperator: "equals",
Value: customerKey
});
var list = [req.Results[0].Name];
var id = req.Results[0].CategoryID;
while(id > 0) {
var req = api.retrieve("DataFolder", ["Name", "ParentFolder.ID"], {
Property: "ID",
SimpleOperator: "equals",
Value: id
});
list.push(req.Results[0].Name);
id = req.Results[0].ParentFolder.ID;
}
list = list.reverse();
var result = list.join(" / ");
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
try {
var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";
var req = api.retrieve("DataExtension", ["Name", "CategoryID"], {
Property: "CustomerKey",
SimpleOperator: "equals",
Value: customerKey
});
var list = [req.Results[0].Name];
var id = req.Results[0].CategoryID;
while(id > 0) {
var req = api.retrieve("DataFolder", ["Name", "ParentFolder.ID"], {
Property: "ID",
SimpleOperator: "equals",
Value: id
});
list.push(req.Results[0].Name);
id = req.Results[0].ParentFolder.ID;
}
list = list.reverse();
var result = list.join(" / ");
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
"Data Extensions / MyFolder / MySubFolder"
Reference
Ressources and references related to the current methods.
Official documentation
SOAP object
List of folder types