locked
How to get the users from the specific team using plugin - MS CRM 2011 RRS feed

  • Question

  • Hi All,

    I have the requirement to get the all users from the specific team using plug-in.

    Any help greatly appriciated..

    Thanks

    Srikanth Reddy

    Saturday, June 7, 2014 11:07 AM

All replies

  • which is the event that will trigger this plugin?

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Saturday, June 7, 2014 11:11 AM
  • Post Create/Update event will trigger this plug-in.
    Saturday, June 7, 2014 11:21 AM
  • Post Create/Update event of which entity? Which is the exact scenario? You can get the users belong to a team easily, but inside the plugin you need to know where to grab the teamid.

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Saturday, June 7, 2014 12:03 PM
  • My Requirement is that in post account create/update I need to create the email activity record to the users of specific team.

    for that I should get the all users email from the specific team and create the email activity on the same.

    thanks in advance

    srikanth reddy

    Sunday, June 8, 2014 8:02 AM
  • You can start from the following code:

    public void Execute(IServiceProvider serviceProvider)
    {
        // Obtain the execution context from the service provider.
        Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
    
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    
        Guid teamId = new Guid("DAC1F19E-03EF-E411-A2BB-D89E67630DBC"); // Id of the specific Team
        QueryExpression userQuery = new QueryExpression("systemuser"); // main query returing users
        userQuery.ColumnSet = new ColumnSet(true); // take all columns
        LinkEntity teamLink = new LinkEntity("systemuser", "teammembership", "systemuserid", "systemuserid", JoinOperator.Inner); // this is the intersect condition
        ConditionExpression teamCondition = new ConditionExpression("teamid", ConditionOperator.Equal, teamId); // this is the condition to use the specific Team
        teamLink.LinkCriteria.AddCondition(teamCondition); // add the condition to the intersect
        userQuery.LinkEntities.Add(teamLink); // add the intersect to the query
        
        EntityCollection retrievedUsers = service.RetrieveMultiple(userQuery); //get the results
        foreach (Entity user in retrievedUsers.Entities) // fetch the results
        {
            var userId = user.Id; // Id of the user
            var userFullName = user.Contains("fullname") ? user["fullname"].ToString() : ""; // FullName of the user
        }
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Sunday, June 8, 2014 12:13 PM