5

I am trying to alter a user's group memberships using the Tridion Core Service. I have a UserData object, so I can get their current GroupMemberships.

I am having trouble adding GroupMemberships to the user's account. Any ideas? Thanks!

1
  • 1
    Could you perhaps provide more information as to what did you tried? what worked? what didn't? errors, stack traces, etc? Sep 30 '13 at 21:17
8

You basically need to add/remove a GroupMemebershipData to your user's GroupMemberships[] data array. Then save user data.

I tried the following code on my T2013 instance and it adds a group membership to the current user (client is an instance of SessionAwareCoreServiceClient):

UserData user = client.GetCurrentUser();
List<GroupMembershipData> groups = new List<GroupMembershipData>(user.GroupMemberships);
GroupMembershipData newGroup = new GroupMembershipData() {
    Group = new LinkToGroupData() {
        IdRef = "tcm:0-10-65568"
    }
};

groups.Add(newGroup);
user.GroupMemberships = groups.ToArray();

client.Save(user, readOptions);

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.