0

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"}
1

I did not included the // initialize WSProxy function, and once I added it, the issue got resolved. Below is the correct code:

 <script type='javascript' runat='server'>
    Platform.Load('core', '1');
    // initialize WSProxy
    var prox = new Script.Util.WSProxy();
    
    var guid = Platform.Function.GUID();
    var name = "Chandan my test de";
    
    
    var de = {
        Name: name,
        CustomerKey: guid,
        CategoryID: xxxxxx,
        Description: "Another DE added via SSJS",
        Fields: [{
            FieldType: "Text",
            Name: "ID",
            MaxLength:18,
            IsPrimaryKey: true,
            IsRequired: true
        },
        {
            FieldType: "Text",
            Name: "Name",
            MaxLength: 200
        }]
    }
        var res = prox.createItem("DataExtension", de);
    
        </script>

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.