0

I need to create a data extension using SSJS in SFMC.

<script runat=server language="JavaScript" executioncontexttype="Post" executioncontextname=test>
var deObj = {
        "CustomerKey" : "demoDE",
        "Name" : "My_Demo_DE",
        "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);
</script>

I used tis code in automation and ran the automation.The automation runs successfully but i cannot find the Data Extension.Please help out!

1

1 Answer 1

-1

It seems it is a problem of lacking "Platform.Load" and the unnecessary code in the first line.

Please use the code below:

<script runat="server">
Platform.Load("core","1.1");
var deObj = {
    "CustomerKey" : "demoDE",
    "Name" : "My Demo DE",
    "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);
</script>

Source

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .