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]);