0

I am trying to create a Data Extension using SSJS Script through Automation Studio.

My script is as follows:

    <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>

But it keep giving me error when I run the automation , even if i only have the platform.load("Core","1.1") line in my script it still shows error :( ..

is that possible to create DE using script through Automation Studio?

If so why platform.load("Core","1.1") is not working for me? Do I need to do anything extra to enable this functions?

Or is there any other way run this script on landing page, if so can some one advice me how to do this?

Many Thanks

1

Platform.Load (used to load the core library) is case sensitive. You will need to use Platform.Load instead of platform.load.

Also, I would recommend removing the comma after the Field 3 object in your array. It will work if you include it, but it's not strictly valid.

The following code works. However, note that the script will fail if a DE already exists with the same name and external key.

<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>

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.