Monday, 16 March 2015

Remove user from Access Team in CRM 2013 and 2015


Here is the C# code to remove the user from the access team.

RemoveUserFromRecordTeamRequest objRemoveUser = new RemoveUserFromRecordTeamRequest();
objRemoveUser.Record = entRecord;
objRemoveUser.SystemUserId = guidSystemUserId;
objRemoveUser.TeamTemplateId = guidTeamTeplateId;
RemoveUserFromRecordTeamResponse response = RemoveUserFromRecordTeamResponse)service.Execute(objRemoveUser);

Record -- Entity Reference object of the record
SystemUserId -- User which you want to remove
TeamTeamplateId -- Access Team Template Guid

Here is the code to get the template guid from template name.

public Guid GetTemplateIDByName(IOrganizationService objService, string strTemplateName)
      Guid guidTeamTeplateId = new Guid();
      //  Query using ConditionExpression and FilterExpression
      ConditionExpression condition = new ConditionExpression();
      //attribute name add to condition
      condition.AttributeName = "teamtemplatename";
      //operator add to condition
      condition.Operator = ConditionOperator.Equal;
      //values added to condition
      // filter creation
      FilterExpression filter = new FilterExpression();
      //condition added
      //create query expression
      QueryExpression query = new QueryExpression("teamtemplate");
      //filter added to query
      //retrieve all columns
      query.ColumnSet = new ColumnSet("teamtemplatename");
      // execute query which will retrieve the Access team teamplate
      EntityCollection accessTeamColl = objService.RetrieveMultiple(query);
      if (accessTeamColl != null && accessTeamColl.Entities.Count > 0)
          guidTeamTeplateId = accessTeamColl.Entities[0].Id;
      return guidTeamTeplateId;

Add user from Access Team CRM 2013 and 2015

Happy CRM'ing


No comments:

Post a Comment