0

I would like to write a single SSJS script that creates a new folder within the Shared Data Extensions tree, and then creates a new Shared Data Extension inside that folder.

I'm able to create the Folder where I would like, no problem.

But I'm wondering if there's a shortcut to then getting the CategoryID of that folder I just created, or do I truly need to do a Folder.retrieve() to get that ID? And if I have to do a Folder.retrieve(), is there a method to ensure I'm retrieving the folder I just created and not any other similarly-named folder(s)?

Thank you!

2 Answers 2

2

You can do it with WSProxy

Platform.Load("Core", "1.1.5");
var api = new Script.Util.WSProxy();
  
var parentFolderId = 00000; // Your first parent folder

var config = {
  "Name": "MyFolder",
  "Description": "My WSProxy created folder",
  "ParentFolder": {
      ID : parentFolderId,
      IDSpecified: true
  },
  "ContentType": "dataextension"
}; // creation details 

// Create Folder and store the result in createResult var    
var createResult = api.createItem("DataFolder", config);

Platform.Function.Stringify(createResult.Results[0].NewID);

Executing the above code, after the createItem function, you get this NewID with the ID of the folder you have just created. So, no need to perform a request to get the Folder ID.

And if I have to do a Folder.retrieve(), is there a method to ensure I'm retrieving the folder I just created and not any other similarly-named folder(s)?

If you choose to use WSProxy you can filter with the exactly name and ContentType, by doing so, you will not retrieve a Content Builder folder with the same name

// Folder fields (properties) you want to retrieve
var folderFields = ["ID", 'ParentFolder.ID', 'Name'];

var folderFitler = {
  LeftOperand: {
    Property: "ID",
    SimpleOperator: 'equals',
    Value: "MyFolder"
  },
  LogicalOperator: "AND",
  RightOperand: {
    Property: "ContentType",
    SimpleOperator: 'equals',
    Value: 'dataextension'
  }
};

var folderRetreiveResult = api.retrieve('DataFolder', folderFields, folderFitler);
Platform.Function.Stringify(folderRetreiveResult.Results[0]);
0

To use a complex filter it is not necessary to use WSProxy. This complex filter can be used as parameter of Folder.Retrieve()

var complexFilter = {
  LeftOperand: {
    Property: "ID",
    SimpleOperator: 'equals',
    Value: "MyFolder"
  },
  LogicalOperator: "AND",
  RightOperand: {
    Property: "ContentType",
    SimpleOperator: 'equals',
    Value: 'dataextension'
  }
};
myFolders = Folder.Retrieve(complexFilter);
1
  • question: is it possible to add another condition to the filter? I mean name = 'myname' and ContentType = 'dataextension' and parentfolder.id = 111111 How?
    – Luis H
    Mar 4, 2022 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .