0

I am attempting to create a new DE in SFMC from a csv file drop using SSJS. There's many resources that references the ability to do this using SSJS, but I am looking for assitance on why it's not working for me. The file is being dropped successfully using triggered_automations Queue Files: On Filename Pattern Settings: Begins with mydatafile_, with step 1 being the ssjs script with the attached code.

<script runat="server">
Platform.Load("Core", "1.1.2");
 try {
      var deObj = {
          CustomerKey: Platform.Function.GUID(),
           Name: "TestDE",
           Fields: [
                    {
                      Name: "Id",
                      FieldType: "Number",
                      IsPrimaryKey: true,
                       IsRequired: true
                    },
                    { Name: "Id", FieldType: "Number", IsPrimaryKey: true, IsRequired: true}
                    { Name: "Text", FieldType: "Text", MaxLength: 100 },
                    { Name: "Date", FieldType: "Date" },
                    { Name: "Field4", FieldType: "Boolean", DefaultValue: "false" },
                    { Name: "Email", FieldType: "EmailAddress", IsRequired: true },
                    { Name: "ZipCode", FieldType: "Text", MaxLength: 5 }
                ],
                CategoryID: 67001
            };
    
            var de = DataExtension.Add(deObj);
    
            if (de && de.Status == "OK") {
                Write("(+) Data Extension was created successfully.<br>");
            } else {
                Write("(!) Data Extension was not created.<br>");
            }
        } catch (err) {
            Write(
                "(!) Data Extension was not created. Error message: " +
                    err.message +
                    "<br>"
            );
        }
</script>

I am having an issue with the automation process. The problem is that after dropping the file, the process is not creating the expected Data Extension (DE) in the specified test folder under the Data Extension category ID of 67001. I have attempted to resolve this issue by adding an executioncontexttype="Post" attribute, but it did not work. Then, I tried using the categoryID from the parent DE folder, but that did not work either. Lastly, I removed all the required text, but that did not work either.

1 Answer 1

0

I have made some adjustments from your code. It should work in order to create a DE.

The main issue is that you put the field "Id" 2 times when you defined the DE.

<script runat="server">
Platform.Load("Core", "1.1.1");
try {
  var deObj = {
      CustomerKey: Platform.Function.GUID(),
      Name: "TestDE",
      Fields: [
          { Name: "Id", FieldType: "Number", IsPrimaryKey: true, IsRequired: true},
          { Name: "Text", FieldType: "Text", MaxLength: 100 },
          { Name: "Date", FieldType: "Date" },
          { Name: "Field4", FieldType: "Boolean", DefaultValue: "false" },
          { Name: "Email", FieldType: "EmailAddress", IsRequired: true },
          { Name: "ZipCode", FieldType: "Text", MaxLength: 5 }
      ],
      CategoryID: 67001
  };

  var de = DataExtension.Add(deObj);
  Write("(+) Data Extension was created successfully." + "<br>");

} catch (err) { 
  Write("(!) Data Extension was not created. Error message: " + err + "<br>")
  }
</script>

You can read this article from Ivan to know how to implement it properly.

3
  • Thank you. With the removal of the additional ID field, it does get created. The only issue now is that no records are being created from the file drop. Here is the text version of the csv sample file: Id Text Date Field4 Email ZipCode 1 Sample text here 4/1/2024 FALSE [email protected] 12345 2 Another sample text 4/2/2024 TRUE [email protected] 54321 3 Text entry example 4/3/2024 FALSE [email protected] 98765 I just noticed that when I manually import the csv file from the DE, it works correctly.
    – Gitconnect
    Commented Apr 1 at 16:01
  • @Nasir when a file drop into the configured location, it will trigger automation to begin. So the file drop itself doesn't push the data to the DE. You would need to create an import activity to import the CSV file to the targeted DE. This leads to: you need to create the DE before the import
    – Duc Le
    Commented Apr 1 at 16:06
  • So the SSJS script above to create the targeted DE can be used in a separate automation or you can manually create the targeted DE for this
    – Duc Le
    Commented Apr 1 at 16:08

You must log in to answer this question.

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