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?

  • what error are you receiving? – Gortonington Mar 26 at 14:26
  • I believe the issue could be permission based. Make sure you have the Administrative Data Management role set. – Gortonington Mar 27 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 at 15:31
1

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);
  • 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. – Gortonington Mar 27 at 21:05

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.