0

Is it possible to retrieve name of all subfolders within parent folder using AMP script and SSJS?

<script runat=server>
    Platform.Load("core","1");
    var results = Folder.Retrieve({Property:"Name",SimpleOperator:"equals",Value:"my emails"});
    Write(Stringify(results));
    </script>

With code i can get only details about specified folder and his parents but I cant see any subfolders.

3

Try this example:

<script runat=server>
Platform.Load("core","1.1.5");
var results = Folder.Retrieve({Property:"ParentFolder.Name",SimpleOperator:"equals",Value:"Journeys"});
Write(Stringify(results));
</script>

Or use WSProxy

<script runat=server>
Platform.Load("core","1.1.5");
var prox = new Script.Util.WSProxy();
var cols = [ "Name","ContentType","ID","CustomerKey"];
var filter = {
    Property: "ParentFolder.Name",
    SimpleOperator: "equals",
    Value: "Journeys"
};
var data = prox.retrieve("DataFolder", cols, filter);
Write(Stringify(data));
</script>
2

Ros has it right, but you should probably use the ParentFolder.ID, instead of the Name. It's entirely possible that there are multiple folders with the same name (in my own accounts, you can usually find tens if not hundreds of folders named "V1.0").

You will also want to make sure you're filtering on the right ContentType value as well. You might look for children of a folder named Journeys, but you have Journeys folders in your Data Extensions, Query Activities, Automations, and other objects. You can find a list of all possible DataFolder ContentType values on this page: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/datafolder.htm

WSProxy is definitely more performant. Getting rid of the call to the core library Platform.Load("core","1.1.5"); will also speed things up. You lose the Write & Stringify functions out of the box, but you can write your own helper functions for them. So Ros' code becomes:

<script runat=server>
function Write(str) {
   Platform.Response.Write(str);
}

/*------------------------------------------*/

function Stringify(obj) {
   return Platform.Function.Stringify(obj);
}

/*------------------------------------------*/

var parentFolderID = 0;
var prox = new Script.Util.WSProxy();
var cols = [ "Name","ContentType","ID","CustomerKey"];
var filter = {
   LeftOperand: {
      Property: "ParentFolder.ID", 
      SimpleOperator: "equals", 
      Value: parentFolderID
   },
   LogicalOperator: "AND",
   RightOperand: {
      Property: "ContentType", 
      SimpleOperator: "equals", 
      Value: 'dataextension'
   }
};
var data = prox.retrieve("DataFolder", cols, filter);
Write(Stringify(data));
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.