2

I'm using following SSJS script to create a Data Extension and set the retention of 7 days at row level:

Platform.Load("core", "1.1");
var deObj = {
    "CustomerKey": "my_DE",
    "Name": "my DE",
    "DataRetentionPeriodLength": 7,
    "DataRetentionPeriod": "Days",
    "DeleteAtEndOfRetentionPeriod": true,
    "RowBasedRetention": false,
    "ResetRetentionPeriodOnImport": false,
    "Fields": [{
            "Name": "id",
            "FieldType": "Text",
            "MaxLength": 100,
            "IsPrimaryKey": true,
            "IsRequired": true
        },
        {
            "Name": "person_id",
            "FieldType": "Text",
            "MaxLength": 80
        }
    ]
};
try {

    var myDE = DataExtension.Add(deObj);

} catch (ex) {
    Write("An error has occurred: " + Stringify(ex));
}

I could not find any documentation around the Retention attributes but I took the SOAP envelope attributes and tried using it in SSJS. But I keep getting error. Are the DataRetentionPeriodLength , DataRetentionPeriod , DeleteAtEndOfRetentionPeriod , RowBasedRetention , ResetRetentionPeriodOnImport not supported with SSJS DataExtension.Add function?

3
  • what error are you receiving? Mar 26, 2019 at 14:26
  • I believe the issue could be permission based. Make sure you have the Administrative Data Management role set. Mar 27, 2019 at 14:18
  • 1
    You are right! I added the role and it worked! the SSJS script does not work from Cloud Pages but worked when run through the Automation
    – raj
    Mar 27, 2019 at 15:31

1 Answer 1

2

As @Gortonington mentioned above DataExtension.Add works of you give Data Manager role. But as we found out from one of our Salesforce Consultant WSProxy works without this role as well. The code he shared was as below:

    Platform.Load("Core","1.1.1");

    var prox = new Script.Util.WSProxy();
    var name = "Retention_Testing";

    var de = {
        Name: name,
        CustomerKey: name,
        Description: "Retention_Testing",
        Fields: [{
            FieldType: "Text",
            Name: "Field1",
            MaxLength: 254,
            IsPrimaryKey: true,
            IsNillable: false,
            IsRequired: true
    },
    {
        FieldType: "Text",
        Name: "Field2",
        MaxLength: 254
    }],
    DataRetentionPeriodLength: 7,
    DataRetentionPeriod: "Days",
    RowBasedRetention: 0,
    ResetRetentionPeriodOnImport: 1,
    DeleteAtEndOfRetentionPeriod: 0
}

  var res = prox.createItem("DataExtension", de);
1
  • As a note, I tried this while logged into a user without the data admin manager permission and it threw an error saying I needed that permission enabled to set retention on DEs. Mar 27, 2019 at 21:05

You must log in to answer this question.

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