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