0

the code for creating a DE is straightforward, but I'm trying to specify where I want this to be created rather than the root DE folder.

Is such a thing possible?

thx

  • can you provide reference to 'the code for creating a DE'. There are multiple routes available to create a DE in SSJS. If you can specify and perhaps share the code, it would likely allow us to better assist you. – Gortonington Mar 14 at 18:04
3

You would just need to add in the CategoryID of the folder you wish to push the DE into.

The SSJS DataExtension Core Library Function operates as a 'short hand' for the API object so you should be able to include all the attributes listed there.

I have tested the following code and it has worked correctly and inserted the DE into my specified folder.

var deObj = {
        "CustomerKey" : "demoDE",
        "Name" : "My Demo DE",
        "CategoryID" : 8675309, /* Put your folder (CategoryID) here */
        "Fields" : [
          { "Name" : "Field 1", "FieldType" : "Number", "IsPrimaryKey" : true, "IsRequired" : true },
          { "Name" : "Field 2", "FieldType" : "Text", "MaxLength" : 50 },
          { "Name" : "Field 3", "FieldType" : "Date", "Ordinal" : 2 },
        ]
    };

var myDE = DataExtension.Add(deObj);
1

You should consider using the new WSProxy; according to the documentation, it's more performant than the existing core library methods. Here's an example from the documentation:

var prox = new Script.Util.WSProxy();

var guid = Platform.Function.GUID();
var name = "my test de - " + guid;

var de = {
    Name: name,
    CustomerKey: guid,
    Description: "Another DE added via SSJS",
    Fields: [{
        FieldType: "Text",
        Name: "ID",
        MaxLength: 36,
        IsPrimaryKey: true,
        IsNillable: false,
        IsRequired: true
    },
    {
        FieldType: "Text",
        Name: "Name",
        MaxLength: 200
    }],
    CategoryID: 101377
}

var res = prox.createItem("DataExtension", de);

Where CategoryID is the ID of the target folder.

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.