0

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

  • /* <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" : 123456 }; var status = myDE.Add(newFolder); </script> */ – R.Pruner Sep 6 '16 at 10:07
2

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

| improve this answer | |
  • Dear Palash, thanks a lot for your answer. I understand what you told me. So I just tried to run the script that you wrote but again doesn't work. I see that the line " var myDEParentFolderID = myDE[0].ID; " gives an Error. What do you think ? – R.Pruner Sep 6 '16 at 13:38
  • I am wrong !!!! I forgot an ">" when I close the javascript code. Great Palash ... Great!!! – R.Pruner Sep 6 '16 at 13:45
  • So Now I can create a Folder path as I wish. I can also create Data Extensions as I wish. Finally I'd want move these DE in the folder requested.....how can I do this ? – R.Pruner Sep 6 '16 at 13:46
  • Do you want to move DE using SSJS OR Manually ? – Palash Rai Sep 7 '16 at 6:34
  • Yes, using SSJS! – R.Pruner Sep 7 '16 at 7:01
0

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>
| 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.