4

I have a user and some groups. I am able to add the groups and with specific scope to the user using core service. What do i do if i need to add a group with all publications as its scope using core service. Below is my sample code.

GroupData group1 = CoreServiceClient.Read("tcm:0-187-65568", null) as GroupData;
UserData userData = CoreServiceClient.Read("tcm:0-49-65552", null) as UserData;

GroupMembershipData groupmembership1 = new GroupMembershipData();

LinkToGroupData linktogroupData1 = new LinkToGroupData();
linktogroupData1.IdRef = group1.Id;
linktogroupData1.Title = group1.Title;

groupmembership1.Group = linktogroupData1;

LinkWithIsEditableToRepositoryData pubLink1 = new LinkWithIsEditableToRepositoryData();
pubLink1.IdRef = "tcm:0-1-1";
pubLink1.Title = "Content";

LinkWithIsEditableToRepositoryData pubLink2 = new LinkWithIsEditableToRepositoryData();
pubLink2.IdRef = "tcm:0-3-1";
pubLink2.Title = "Design";

LinkWithIsEditableToRepositoryData[] pubArray1 = { pubLink1, pubLink2 };
groupmembership1.Scope = pubArray1;

GroupMembershipData[] groupArray = { groupmembership1 };
userData.GroupMemberships = groupArray;

CoreServiceClient.Save(userData, null);

2 Answers 2

4

If you want the Group to be available in all Publications (including future ones), simply leave the Scope property alone. The default value is the same as checking that "(All Publications)" checkbox on the editing screen.

3

The questions narrows down to how to get all publications:

var allPublications = CoreServiceClient.GetSystemWideList(new RepositoryFilterData()); 

And now just assign it:

groupmembership1.Scope = allPublications.Select(pub => new LinkWithIsEditableToRepositoryData{ IdRef = pub.Id }).ToArray();

I was writing it without checking first, so there might be some typos

2
  • Actually, that would include only the Publications available at the time of the save -- equivalent to checking the box next to each Publication in the editing screen. The Group would not be available in any new Publications created later. Commented Sep 15, 2014 at 15:51
  • Indeed, even more, only publications available to current user. As far as I remember scope should be empty for all publications. The easiest way to check is to make the setup in the GUI and then read publication to see what should be set Commented Sep 16, 2014 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.