I have created a HTML landing page like below, which takes the input from the user for Data Extension name
<html>
<body>
<h1>
Create a new Data Extension
</h1>
<form action="{{URL_OF_SSJS_CODE_RESOURCE}}" method="post">
<label for="dename">Data Extension Name:</label><br>
<input type="text" name="dename">
<input type="submit" value="Create & Copy">
</form>
</body>
</html>
Then on form submit the DE name is passed to SSJS code resource (in order to create a new DE entered by user) which looks like below
<script runat="server">
Platform.Load("Core","1");
try{
var deName = Request.GetFormField("dename");
Write("DE Name is...." + deName);
}
catch(err)
{
Write("error is.."+err);
}
/* fetch folder */
var FolderAttributes = Folder.Retrieve({ Property: "Name", SimpleOperator: "equals", Value:"Test_Create"});
var FolderID = FolderAttributes[0].ID;
//create DE
try{
var obj1={
"Name" :deName,
"CustomerKey" : deName,
"CategoryID": FolderID,
"Fields": [
{ "Name" : "name", "FieldType" : "Text", "MaxLength" : 50 }
]
};
/* function*/
var myDe=DataExtension.Add(obj1);
}
catch(err)
{
Write ("cannot create DE: "+err);
}
</script>
The DE Name is passed to the SSJS page but still I am not able to create a DE and get the caught error. Could anyone point where I am doing wrong and how to fix this code so that the DE gets created. When I try to create the DE in automation studio (by passing static values), I can successfully create the DE.