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

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]);
| improve this answer | |

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.