-1
<script type="text/javascript" runat='server'>
Platform.Load("Core", "1.1");

var DEParentFolderID = '0000';
//var QRYParentFolderID = '0000';

var SubAdhocDE = DataExtension.Init("adhoc_master_import");
    var ControlRows = SubAdhocDE.Rows.Retrieve();

          var ControlName = ControlRows[0]['segment_name'];     
    var Today = Format(Now(),"MM/dd/yyyy");
    var DENamingConvention = 'adhoc_'+ ControlName +'_control_'+ Today;

    //Init to check for DE
    var DECheck = DataExtension.Init(DENamingConvention);
    var fields = DECheck.Fields.Retrieve();

    //if DE doesn't exist create one
    if (fields.length == 0) {
        var deObj = {

            Name : DENamingConvention,
            CategoryID : DEParentFolderID,       
            Fields : [
{ "Name" : "email_address", "FieldType" : "EmailAddress", "IsRequired" : true },
{ "Name" : "account_id", "FieldType" : "Text", "MaxLength" : 25, "IsRequired" : true },
{ "Name" : "dim_account_key", "FieldType" : "Text", "MaxLength" : 20},
{ "Name" : "handle", "FieldType" : "Text", "MaxLength" : 64},
{ "Name" : "optin_status_direct", "FieldType" : "Text", "MaxLength" : 20},
{ "Name" : "segment_name", "FieldType" : "Text", "MaxLength" : 60},
{ "Name" : "country_code", "FieldType" : "Text", "MaxLength" : 2},
{ "Name" : "province_code", "FieldType" : "Text", "MaxLength" : 3},
{ "Name" : "language_code", "FieldType" : "Text", "MaxLength" : 2},
{ "Name" : "voucher_code", "FieldType" : "Text", "MaxLength" : 60},
{ "Name" : "voucher_expiration_date", "FieldType" : "Date"},
{ "Name" : "offer_description", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "product_name", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "pdp_url", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "device_name", "FieldType" : "Text", "MaxLength" : 20},
{ "Name" : "ps4_flag", "FieldType" : "Text", "MaxLength" : 1},
{ "Name" : "copy1", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "copy2", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "copy3", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "copy4", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "esrb_logo_url", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "esrb_rating", "FieldType" : "Text", "MaxLength" : 20},
{ "Name" : "esrb_description", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "img_url1", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "img_url2", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "img_url3", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "img_url4", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "img_url5", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "img_url6", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard1", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard2", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard3", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard4", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard5", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard6", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard7", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard8", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard9", "FieldType" : "Text", "MaxLength" : 2000},
{ "Name" : "wildcard10", "FieldType" : "Text", "MaxLength" : 2000}
                ],
            SendableInfo : {
                Field : { "Name" : "email_address", "FieldType" : "EmailAddress" },
            RelatesOn : "Subscriber Key"}
            };
        var myDE = DataExtension.Add(deObj);
    }
Write(myDE);
</script>
3
  • @jagular: did u find any problem in this code?
    – SFMC_User
    Commented Nov 10, 2015 at 20:42
  • Sorry, I just fixed the formatting. I find it very distracting when only half the code gets formatted. It's not hard; it's just not like anything I've used previously.
    – Jagular
    Commented Nov 10, 2015 at 20:57
  • No no, I mean to say that did you find any mistake in this code and thanks a lot for formatting.
    – SFMC_User
    Commented Nov 10, 2015 at 21:00

1 Answer 1

3

I was able to take your code sample and get it to work after a few modifications.

Issues:

  • Need to specify CustomerKey in the JSON object.
  • Invalid characters in data extension name. I was not able to make the call when the data extension name contained / or -. But, I was able to create the DE after formatting the date as yyyyMMdd.
  • Reformat JSON Although the SFMC online help shows the same formatting as your example. I was only able to get the code to work after reformatting the JSON. Notice the double quotes around the Name, CustomerKey, Fields objects.

Code:

var deObj = {
    "Name": DENamingConvention,
    "CustomerKey": DENamingConvention,
    "Fields": [
        {"Name": "email_address", "FieldType": "EmailAddress", "IsRequired": true}, 
        {"Name": "account_id", "FieldType": "Text", "MaxLength": 25, "IsRequired": true},
        {"Name": "dim_account_key", "FieldType": "Text", "MaxLength": 20},
        {"Name": "handle", "FieldType": "Text", "MaxLength": 64},
        {"Name": "optin_status_direct", "FieldType": "Text", "MaxLength": 20},
        {"Name": "segment_name", "FieldType": "Text", "MaxLength": 60},
        {"Name": "country_code", "FieldType": "Text", "MaxLength": 2},
        {"Name": "province_code", "FieldType": "Text", "MaxLength": 3},
        {"Name": "language_code", "FieldType": "Text", "MaxLength": 2},
        {"Name": "voucher_code", "FieldType": "Text", "MaxLength": 60},
        {"Name": "voucher_expiration_date", "FieldType": "Date"},
        {"Name": "offer_description", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "product_name", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "pdp_url", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "device_name", "FieldType": "Text", "MaxLength": 20},
        {"Name": "ps4_flag", "FieldType": "Text", "MaxLength": 1},
        {"Name": "copy1", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "copy2", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "copy3", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "copy4", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "esrb_logo_url", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "esrb_rating", "FieldType": "Text", "MaxLength": 20},
        {"Name": "esrb_description", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "img_url1", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "img_url2", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "img_url3", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "img_url4", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "img_url5", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "img_url6", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard1", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard2", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard3", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard4", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard5", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard6", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard7", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard8", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard9", "FieldType": "Text", "MaxLength": 2000},
        {"Name": "wildcard10", "FieldType": "Text", "MaxLength": 2000}
    ],
    "SendableInfo": {
        "Field": {"Name": "email_address", "FieldType": "EmailAddress"}, "RelatesOn": "Subscriber Key"
    }
};
1
  • By the way, I removed the "CategoryID" from the JSON object in my test. You shouldn't have an issue adding it back. I had removed it since my test environment did not contain a folder for category_id 9610. FYI, removing the "CategoryID" will create the data extension in the root folder. Commented Nov 10, 2015 at 21:40

You must log in to answer this question.

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