1

While trying to create a Data Extension with data retention using WSProxy, I am getting the following error:

The Data Extension Manage Data Retention user permission must be set in order to use the Data Extension Retention policies

I have double-checked that the above permissions are granted for my user:

enter image description here

Unfortunately, the error persists. Below is the code I am running on a CloudPage:

<script runat="server">
    Platform.Load("core", "1.1.1");
 
    var prox = new Script.Util.WSProxy();

 try {
 
    var name = "Retention_Test";

    var de = {
        Name: name,
        CustomerKey: name,
        Description: "Retention_Test",
        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);  

   
  Write(Stringify(res));
  
 } catch(error) {
  Write(Stringify(error));
 } 
</script>

This code works without any problems when run in Automation Studio. Unfortunately, I need to be able to run this on a CloudPage.

Any ideas will be welcome!


EDIT: I've tried impersonation via WSProxy in two ways:

prox.setClientId({"ID": Platform.Function.AuthenticatedMemberID()});

and hardcoding the ID as referenced in the documentation:

prox.setClientId({ "ID": 1xxxx378, "UserID": 1xxxx378 });

and was getting the exact same error message:

The Data Extension Manage Data Retention user permission must be set in order to use the Data Extension Retention policies

4
  • 1
    cloudpages don't execute in the context of your user
    – EazyE
    Commented Dec 7, 2021 at 18:09
  • Is there a way to pick in which users context this should be executed in? Like described in this documentation (which I’ve tried and also couldn’t get to work btw): developer.salesforce.com/docs/…
    – zuzannamj
    Commented Dec 7, 2021 at 18:11
  • there is a KI trailblazer.salesforce.com/issues_view?id=a1p4V000001aFGmQAM that this isn't going to be fixed
    – EazyE
    Commented Dec 7, 2021 at 19:08
  • What EazyE says, but you can still do this from the cloudpage, you'll just have to send an API call. Creating DEs with retention works perfectly fine through an Installed Package and SOAP API. I agree it would be much easier with "native" methods (especially when the only gap is retention and everything else is already fine), but there is at least a workaround. Commented Dec 8, 2021 at 8:05

2 Answers 2

2

So, this is not exactly a simple solution and it has some extra steps to get done, but I have found that if you use the setClientId() impersonation in WSProxy to also set the userID then you can get past this issue of permission. As a note though, only the AccountUserID (int only) gathered from the SSJS AccountUser.Retrieve function will work here (that I know of). And that user you retrieve needs to have the 'Administrative Data Management' Role in order for it to work.

The only caveat around this being that AccountUser only works at the parent level - which causes limits. What I have done to get past this is to run a script in the parent that fills a DE that has the user customerkey as the primary key and then the ID in another field and have this be a shared DE to grab info from to use this in other business units.

As an example:

<script runat="server">

Platform.Load("core", "1.1");
try {
/* Create New DE */
var mid = 123456;  //MID of the account
var user = AccountUser.Retrieve({Property:"CustomerKey",SimpleOperator:"equals",Value:"myExternalKey"})[0].AccountUserID;  
//Int UserID not string version
//need to access via accountUser SSJS in microsite: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_accountUserFunctions.htm
//User needs to have 'Administrative Data Management' Role to set Retention
  
var prox = new Script.Util.WSProxy();

/* Set ClientID */
prox.setClientId({ "ID": mid, "UserID" : user }); //Impersonates the BU

var de = {
    "CustomerKey": "my_DE",
    "Name": "my DE",
    "DataRetentionPeriodLength": 7,
    "DataRetentionPeriod": "Days",
    "DeleteAtEndOfRetentionPeriod": false,
    "RowBasedRetention": true,
    "ResetRetentionPeriodOnImport": false,
    "Fields": [{
            "Name": "id",
            "FieldType": "Text",
            "MaxLength": 100,
            "IsPrimaryKey": true,
            "IsRequired": true
        },
        {
            "Name": "person_id",
            "FieldType": "Text",
            "MaxLength": 80
        }
    ]
};

var res = prox.createItem("DataExtension", de);
Write('<br>' + Stringify(res))
} catch(e) {
  Write(Stringify(e))
}
</script>
2
  • 1
    Thanks, Greg, that did the trick! And I guess worst case I can just hardcode the user ID, since I want all my end users to be able to use it - thank you :-)
    – zuzannamj
    Commented Dec 9, 2021 at 15:22
  • Glad that works and agreed, hard coding the ID certainly is an option if you just need the one ID. Commented Dec 9, 2021 at 15:24
0

To solve this out you need to add WSProxy impersonation and it will be enough to avoid the error.

var prox = new Script.Util.WSProxy();
prox.setClientId({"ID": Platform.Function.AuthenticatedMemberID()});

Note: also not sure why do you load Core library and initialize WSProxy 2 times.

2
  • Unfortunately I'm getting the same error, I've updated the original question
    – zuzannamj
    Commented Dec 8, 2021 at 10:28
  • Weird. Was getting the same initial error and then after impersonation with only "ID": MID, the script correctly created the DE.
    – Niko
    Commented Dec 8, 2021 at 10:43

You must log in to answer this question.

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