I am new to SSJS and trying to create a test DE. But it's failing. I have created the below cloud page to troubleshoot the error.
%%[
VAR @Result
]%%
<script runat="server">
Platform.Load("core","1");
try {
var guid = Platform.Function.GUID();
var name = "Chandan my test de";
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
}]
}
var res = prox.createItem("DataExtension", de);
}
catch (ex) {
Write("An error has occurred: " + Stringify(ex));
Variable.SetValue("@Result", Stringify(ex)); //sets above ampscript variable
}
</script>
//// some basic page html goes here/////
%%=v(@Result)=%%
The error shown is
An error has occurred: {"message":"Object expected: createItem","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(VariableDeclarationStatement statement)\r\n at Jint.Expressions.VariableDeclarationStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: createItem\r\nException of type 'Jint.Native.JsException' was thrown.
- from Jint\r\n\r\n"} //// some basic page html goes here///// {"message":"Object expected: createItem","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(VariableDeclarationStatement statement)\r\n at Jint.Expressions.VariableDeclarationStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: createItem\r\nException of type 'Jint.Native.JsException' was thrown.
- from Jint\r\n\r\n"}