Loading

Marketing Cloud | User Roles, Permissions and Business Unit Assignments

Data pubblicazione: Mar 17, 2025
Descrizione

An audit may be needed to determine all users, their roles, permissions sets and the default Business Unit assigned as well as Business Units they have access to.  This can be performed by an administrator by running a script activity in Automation Studio which will write the data to Data Extensions that can then be extracted using a data extract.

Risoluzione
  1. Create three standard Data Exstensions
  2. Use the following field names and field types.

 

DE Name: USERS_PERMISSIONS

Fieldtype FieldName Text AccountUserID Text Name Text Description Number ID Boolean IsAllowed Boolean IsDenied Boolean IsShareable Text ObjectType DE Name: USERS_ROLES

Fieldtype FieldName Text AccountUserID Text Name Text Description Text CustomerKey Boolean IsSystemDefined Text ObjectID DE Name: USERS_INFORMATION

Fieldtype FieldName Text UserID Text Name Text Email Boolean ActiveFlag Number Delete Date LastSuccessfulLogin Boolean IsAPIUser Text NotificationEmailAddress Text IsLocked Number ID Text CustomerKey Text AccountUserID

3. Create an SSJS Script activity in automation Studio using the following code:

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

try {
    var usersInformationTable = "USERS_INFORMATION";
    var usersRolesTable       = "USERS_ROLES";
    var usersPermissionsTable = "USERS_PERMISSIONS";

    var queryAllAccounts = true;
    var cols = [
        "AccountUserID",
        "ActiveFlag",
        "CustomerKey",
        "Email",
        "ID",
        "LastSuccessfulLogin",
        "ModifiedDate",
        "Name",
        "Roles",
        "UserID",
        "UserPermissions"
    ];

    // WSProxy retrieve
    var res = prox.retrieve("AccountUser", cols/*, filter*/);

    if (res.Status == "OK") {

        var resultUsers = res.Results;
        for (i in resultUsers) {
            var rows = Platform.Function.InsertData(usersInformationTable,
                                                    ["AccountUserID",
                                                     "Name",
                                                     "UserID",
                                                     "Email",
                                                     "NotificationEmailAddress",
                                                     "ActiveFlag",
                                                     "Delete",
                                                     "LastSuccessfulLogin",
                                                     "IsAPIUser",
                                                     "IsLocked",
                                                     "ID",
                                                     "CustomerKey"],
                                                    [resultUsers[i].AccountUserID,
                                                     resultUsers[i].Name,
                                                     resultUsers[i].UserID,
                                                     resultUsers[i].Email,
                                                     resultUsers[i].NotificationEmailAddress,
                                                     resultUsers[i].ActiveFlag,
                                                     resultUsers[i].Delete,
                                                     resultUsers[i].LastSuccessfulLogin,
                                                     resultUsers[i].IsAPIUser,
                                                     resultUsers[i].IsLocked,
                                                     resultUsers[i].ID,
                                                     resultUsers[i].CustomerKey]);

            var userRoles = resultUsers[i].Roles;
            for (j in userRoles) {
                var rows = Platform.Function.InsertData(usersRolesTable,
                                                      ["AccountUserID",
                                                       "Name",
                                                       "Description",
                                                       "CustomerKey",
                                                       "IsSystemDefined",
                                                       "ObjectID"],
                                                      [resultUsers[i].AccountUserID,
                                                       userRoles[j].Name,
                                                       userRoles[j].Description,
                                                       userRoles[j].CustomerKey,
                                                       userRoles[j].IsSystemDefined,
                                                       userRoles[j].ObjectID]);


                var cols_roles = ["Permissions"];
                var filter_roles = {
                        Property: "ObjectID",
                        SimpleOperator: "equals",
                        Value: userRoles[j].ObjectID
                };

                var resRoles = prox.retrieve("Role", cols_roles, filter_roles);

                for (var k=0; k<resRoles.Results.length; k++) {

                    var permissionsArray = resRoles.Results[k].Permissions;

                    for (x in permissionsArray) {
                        var rows = Platform.Function.InsertData(usersPermissionsTable,
                                                          ["AccountUserID",
                                                           "Name",
                                                           "Description",
                                                           "ObjectType",
                                                           "ID",
                                                           "IsAllowed",
                                                           "IsDenied",
                                                           "IsShareable"],
                                                          [resultUsers[i].AccountUserID,
                                                           permissionsArray[x].Name,
                                                           permissionsArray[x].Description,
                                                           permissionsArray[x].ObjectType,
                                                           permissionsArray[x].ID,
                                                           permissionsArray[x].IsAllowed,
                                                           permissionsArray[x].IsDenied,
                                                           permissionsArray[x].IsShareable]);
                    }
                }
            }
        }
    }
} catch (error) {
    Write(Stringify(error));
}
</script>

4.  Add the script to an automation and then run the script using the Run Once function

Numero articolo Knowledge

004517766

 
Caricamento
Salesforce Help | Article