locked
Team and BU membership lists RRS feed

  • Question

  • Hi all,

    I'm trying to get a list of users that belong to a specific team/BU for a CRM plugin, and I'm not quite sure how to go about it. A quick search of the forums for the word "team" didn't reveal anything useful, unfortunately.

    I need to get a list of systemusers that belong to a team and a BU; I have the team/BU id. Any pointers?

    Cheers,

    Anu

    Friday, May 28, 2010 3:04 PM

Answers

  • or if you  want  to reterive all  the members  of the team,  then  use ReteriveMembersTeam, see the  link below.

    http://msdn.microsoft.com/en-us/library/bb959489.aspx


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    • Marked as answer by anuruddha.j Friday, May 28, 2010 3:41 PM
    Friday, May 28, 2010 3:33 PM
  • Hi.

     

    Try for team following:

     

        QueryExpression query = new QueryExpression(EntityName.systemuser.ToString());
        query.ColumnSet = new ColumnSet(new string[] { "systemuserid" });
        LinkEntity link = query.AddLink("teammembership", "systemuserid", "systemuserid");
        link.LinkCriteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, teamid));
    
        List<BusinessEntity> users = crmservice.RetrieveMultiple(query).BusinessEntities;
    
        foreach (systemuser user in users)
        {
    //do some action with users
        }

    for business unit:

     

     

    QueryByAttribute query = new QueryByAttribute();
    query.Attributes = new string[] { "businessunitid" };
    query.ColumnSet = new AllColumns();
    query.Values = new object[] { businessunitid };
    query.EntityName = EntityName.systemuser.ToString();
    
    List<BusinessEntity> users = crmservice.RetrieveMultiple(query).BusinessEntities;
    
    foreach (systemuser user in users)
    {
    	//do some action with users
    }

     


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by anuruddha.j Friday, May 28, 2010 3:42 PM
    Friday, May 28, 2010 3:38 PM
    Moderator

All replies

  • Hey Anu

    If you want to get list of systemuser, blongs to specific business unit you can query to systemuser entity itself

    check retrievemultiple function of crmwebservice

    http://msdn.microsoft.com/en-us/library/bb929002(v=MSDN.10).aspx

    Hope it will help you !!!


    Mahain
    Friday, May 28, 2010 3:17 PM
    Moderator
  •  

    The following example demonstrates how to use the RetrieveTeamsSystemUser message.

    Retrieves the list of teams of which the specified user is a member.

    [C#]
    // Set up the CRM service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0; 
    token.OrganizationName = "AdventureWorksCycle";
     
    CrmService service = new CrmService();
    service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    // Create the request.
    RetrieveTeamsSystemUserRequest teamsSystemUserRequest = new RetrieveTeamsSystemUserRequest();
    teamsSystemUserRequest.EntityId = ((systemuser)crmUser.BusinessEntities[0]).systemuserid.Value;
    // Be aware that using AllColumns may adversely affect
    // performance and cause unwanted cascading in subsequent 
    // updates. A best practice is to retrieve the least amount of 
    // data required.
    teamsSystemUserRequest.ColumnSet = new AllColumns();
    // Execute the request.
    RetrieveTeamsSystemUserResponse teamsSystemUserResponse = (RetrieveTeamsSystemUserResponse)service.Execute(teamsSystemUserRequest);
    [

    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Friday, May 28, 2010 3:29 PM
  • or if you  want  to reterive all  the members  of the team,  then  use ReteriveMembersTeam, see the  link below.

    http://msdn.microsoft.com/en-us/library/bb959489.aspx


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    • Marked as answer by anuruddha.j Friday, May 28, 2010 3:41 PM
    Friday, May 28, 2010 3:33 PM
  • Hi.

     

    Try for team following:

     

        QueryExpression query = new QueryExpression(EntityName.systemuser.ToString());
        query.ColumnSet = new ColumnSet(new string[] { "systemuserid" });
        LinkEntity link = query.AddLink("teammembership", "systemuserid", "systemuserid");
        link.LinkCriteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, teamid));
    
        List<BusinessEntity> users = crmservice.RetrieveMultiple(query).BusinessEntities;
    
        foreach (systemuser user in users)
        {
    //do some action with users
        }

    for business unit:

     

     

    QueryByAttribute query = new QueryByAttribute();
    query.Attributes = new string[] { "businessunitid" };
    query.ColumnSet = new AllColumns();
    query.Values = new object[] { businessunitid };
    query.EntityName = EntityName.systemuser.ToString();
    
    List<BusinessEntity> users = crmservice.RetrieveMultiple(query).BusinessEntities;
    
    foreach (systemuser user in users)
    {
    	//do some action with users
    }

     


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by anuruddha.j Friday, May 28, 2010 3:42 PM
    Friday, May 28, 2010 3:38 PM
    Moderator
  • Thanks for your help, all - I got a bit lost in the CRM SDK and didn't notice the RetrieveMembersTeam message. Thanks for the rapid response - I'll try out the code and get back to you!

    Anu

    Friday, May 28, 2010 3:44 PM