Add user to Access Team CRM 2013 and 2015

Hello,

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

// Add Account User to Access Team
AddUserToRecordTeamRequest teamAddRequest = new AddUserToRecordTeamRequest();
teamAddRequest.Record = erfRecord;
teamAddRequest.SystemUserId = guidSystemUserId;
teamAddRequest.TeamTemplateId = guidTeamTeplateId;
AddUserToRecordTeamResponse response = (AddUserToRecordTeamResponse)service.Execute(teamAddRequest);

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;
}

Remove user from Access Team in CRM 2013 and 2015


Happy CRM’ing
Gopinath

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s