SSJS Activities: Create Folder path

I am writing to know how can I do several actions on a Data Extension and Create Folder using Javascript by SSJS

Currently I can not create a folder.
I do not understand what is the problem .
By the way the only tool in Marketing Cloud that tells me if the script is successful is the “Automation” that I created specifically which tells me if the script is “Completed” or gives “Error”.

Definitely something wrong in the JavaScript code. However I ask you to assist me at least to create a sub-folder under the folder “Data Extensions”. Can you tell me if this code is correct or not?

<script runat=server>

Platform.Load("core","1");

var myDE = Folder.Retrieve({Property:"Name",SimpleOperator:"equals",Value:"Data Extensions"});
myDE.SetID(12345);

var newFolder = {
    "Name" : "Folder Script",
    "CustomerKey" : "test_folder_key",
    "Description" : "Test added",
    "ContentType" : "dataextension",
    "IsActive" : "true",
    "IsEditable" : "true",
    "AllowChildren" : "false",
    "ParentFolderID" : 12345
};

var status = myDE.Add(newFolder);

</script>

Regards
Riccardo Pruner

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

you require Parent Folder ID to create the folder path and same need to pass in ParentFolderID DataFolder object properties.

You can hard code your DataExtension Folder ID OR you can get dynamically by using SSJS link below:

<script runat=server>

Platform.Load("core","1");

var myDE = Folder.Retrieve({Property:"ContentType",SimpleOperator:"equals",Value:"dataextension"});
var myDEParentFolderID = myDE[0].ID;

var newFolder = {
    "Name" : "Folder Script",
    "CustomerKey" : "Folder Script",
    "Description" : "Test added",
    "ContentType" : "dataextension",
    "IsActive" : "true",
    "IsEditable" : "true",
    "AllowChildren" : "false",
    "ParentFolderID" : myDEParentFolderID
};

var status = Folder.Add(newFolder);
Write(status);

</script>

Result:
OK

Method 2

thanks for the advice.
I’d like to create this folder path. I attach a img to show a sample path that I would want to create. Then I try to write a sample code where I create a Father Folder e the first Child Folder.
Unfortunatly this code doen’t work. Any suggestionss ?

enter image description here

<script runat=server>

Platform.Load("core","1");

var DE = Folder.Retrieve({Property:"Name",SimpleOperator:"equals",Value:"My Emails"});
var DEParentFolderID = DE[0].ID;

var folderONE = {
    "Name" : "2016",
    "CustomerKey" : "folder_script",
    "Description" : "forlderPath",
    "ContentType" : "email",
    "IsActive" : "true",
    "IsEditable" : "true",
    "AllowChildren" : "false",
    "ParentFolderID" : DEParentFolderID
};

var status = Folder.Add(folderONE);
Write(status);

var myDE = Folder.Retrieve({Property:"Name",SimpleOperator:"equals",Value:"2016"});
var myDEParentFolderID = myDE[0].ID;

var folderTWO = {
    "Name" : "Commerciali",
    "CustomerKey" : "folder_script1",
    "Description" : "forlderPath",
    "ContentType" : "email",
    "IsActive" : "true",
    "IsEditable" : "true",
    "AllowChildren" : "false",
    "ParentFolderID" : myDEParentFolderID
};

var status = Folder.Add(folderTWO);
Write(status);

</script>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x