7

I am looking for code to list all groups; name, tcm, description. I then want to list all users in these groups. I am working on a report. Also, if anyone knows of a good reference site or book for CoreService development, that would be great. THank you

9

There is already a load of useful core-service examples here on stack exchange, i'd imagine a simple search will get you enough examples to build something for your own needs.

I did find a bit of code on my own machine to get a list of groups for a user, i know this isn't what you need, but it's similar and with a bit of tweaking will get you to where you need to be:

public List<string> GetUserGroups(string TrusteeID)
{
    List<string> userGroups = new List<string>();
    TrusteeData trustee = (TrusteeData)[YOUR_CORESERVICE_OBJECT].Read(TrusteeID, new ReadOptions());

    GroupMembershipData[] GroupMemberships = trustee.GroupMemberships;

    foreach (GroupMembershipData grpData in GroupMemberships)
    {
        userGroups.Add(grpData.Group.IdRef);
    }

    return userGroups;
}

Note i've spelled out the YOUR_CORESERVICE_OBJECT - this needs to be the instance of your core service object :)

| improve this answer | |
  • I will do some deeper digging here on the site. Thank you for your answer. – BryanD Jun 26 '13 at 12:52
8

Here are some ideas, I think this should get you started.

var groups = _session.GetSystemWideList(new GroupsFilterData() {IsPredefined = false, BaseColumns = ListBaseColumns.IdAndTitle});
foreach(var group in groups)
{
   string groupName = group.Title;
   string tcmUri = group.Id;
   string description = group.Description
   var users = group.
}

I'm afraid it is not possible to fetch a list of users from a group object, so you will have to get a list of users, and check which groups they are member of. In the end this will gather all the data you need for your report.

The list of all users (GetSystemWideList) will get only the basic user information, a Read() is required to get the full UserData object with properties like GroupMemberships.

var allUsers = _session.GetSystemWideList(new UsersFilterData { IsPredefined = false, BaseColumns = ListBaseColumns.IdAndTitle });
foreach (var user in allUsers)
{
   var userData = (UserData) _session.Read(user.Id, new ReadOptions());
   string userName = user.Title;
   bool isAdministrator = user.Privileges == 1 ? true : false;
   var groupMemberships = user.GroupMemberships.Select(g => g.Group.IdRef);
}

To learn more about the available operations on the CoreService you could read the ICoreService2011 Members section of the Core Service API reference documentation (chm file).

There is no book about the CoreService, but you can find some Stackexhange and Stackoverflow answers and some blogs and code snipplets.

| improve this answer | |
  • Thank you. I will give this a try. I'm not sure if it's just me but developing for Core Service seems to be too complex and especially if you are simply trying to get some reports. It would be easier to simply grab the data directly from the database. Thanks again. – BryanD Jun 26 '13 at 12:50
  • Continue trying, I think you have to get through a learning curve here. I uses Core Service for reporting, I found it easy to use and test. Now I would prefer the Core Service over a database query. Also, you should not tamper or even read from the database. In some cases the XML data stored in the db is not even the same you would get through the Core Service or TOM.NET API. – Jan H Jun 26 '13 at 13:04

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.