Monday, 16 March 2015

Remove user from Access Team in CRM 2013 and 2015

Hello,

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
      condition.Values.Add(strTemplateName);
      // filter creation
      FilterExpression filter = new FilterExpression();
      //condition added
      filter.Conditions.Add(condition);
      //create query expression
      QueryExpression query = new QueryExpression("teamtemplate");
      //filter added to query
      query.Criteria.AddFilter(filter);
      //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
Gopinath

 

No comments:

Post a Comment