SSJS Functions in Automation Studio

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 keeps giving me an 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 these functions?

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

Many Thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x