Showing posts with label access Teams. Show all posts
Showing posts with label access Teams. Show all posts

Monday, February 13, 2017

Error : Too many entities enabled for auto created access teams.



Error Log: 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Too many entities enabled for auto created access teams.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147187918</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
  <Message>Too many entities enabled for auto created access teams.</Message>
  <Timestamp>2017-02-13T21:33:05.6114604Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText i:nil="true" />
</OrganizationServiceFault>


Solution: 
In MS CRM by default you can enable for auto create access teams to Maximum 5 entities. Once this limit reaches you will see above error message.
This limit is specified in MaxEntitiesEnabledForAutoCreatedAccessTeams deployment setting.
You need to update this deployment setting if you have more than 5 entities.

To update you can use Powershell

Add-PSSnapin Microsoft.Crm.PowerShell
$Cred = Get-Credential
$CrmOrgs=Get-CrmOrganizations -serverUrl https://< CRM_Server_Host >
 -Credential $Cred
Get-CrmSetting -SettingType TeamSettings
$set =Get-CrmSetting -SettingType TeamSettings
$set.MaxEntitiesEnabledForAutoCreatedAccessTeams = “6”
Set-CrmSetting -Setting $set
 
Useful links for PowerShell:
https://technet.microsoft.com/en-us/library/dn905215.aspx#BKMK_changemon
https://technet.microsoft.com/en-us/library/dn531194.aspx
https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.deployment.teamsettings.maxentitiesenabledforautocreatedaccessteams(v=crm.7).aspx 

To Update using SQL
Login to SQL server
Run following query on MSCRM_CONFIG database
select * from DeploymentProperties where ColumnName ='MaxEntitiesEnabledForAutoCreatedAccessTeams'

To Update MaxEntitiesEnabledForAutoCreatedAccessTeams  setting run
update DeploymentProperties set IntColumn = 6 where ColumnName ='MaxEntitiesEnabledForAutoCreatedAccessTeams'

Verify your setting is changed or not using select query.
Now you can able to enable 6th entity for auto create access team. 

Thursday, May 5, 2016

Add / remove users to Access team dynamically

Sometime we need to add users into access teams when record is created or based on some business logic.

From MS CRM 2013 Microsoft introduced access teams.

For information about access team
 Use access teams and owner teams to collaborate and share information

You can enable access team for entity and create access team templates.

Here is more information on how to create access team template and add to form.
Create Access Teams

when you created access team template you can add it to form and add users manually to give access to record, but some time we need to it automatically.

To do automatically, you can use  AddUserToRecordTeamRequest messge.

AddUserToRecordTeamRequest addReq = new AddUserToRecordTeamRequest()
       {
         Record = Record Entity Reference,
         SystemUserId = UserId,
         TeamTemplateId = TemplateId

       };

service.Execute(addReq);

and use Execute to pass this request.

If want to do add user into multiple records access Team.

public void AddUserToAccessTeam(IOrganizationService service, List<EntityReference> lstentref, string templateName, Guid loggedInUser, Guid? TemplateId)
        {
         using (XrmServiceContext Xrmcontext = new XrmServiceContext(service))                                  {
                Guid teamTemplate = new Guid();

                if (TemplateId == null || TemplateId.Value == Guid.Empty)
                    /*Get Access Team Template from Template Name*/
                    teamTemplate = Xrmcontext.TeamTemplateSet.Where(ttm => ttm.TeamTemplateName == templateName).Select(ttm => ttm.TeamTemplateId.Value).FirstOrDefault();
                else
                    teamTemplate = TemplateId.Value;

                int count = 0;
                int TotalRecord = lstentref.Count();
                int recordRemaining = TotalRecord;

                /*Initialize multiple request*/
                ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
                {
                    Settings = new ExecuteMultipleSettings()
                    {
                        ContinueOnError = true,
                        ReturnResponses = true
                    },
                    Requests = new OrganizationRequestCollection()
                };

                foreach (EntityReference entRef in lstentref)
                {
                    recordRemaining--;
                    /*Add user to Record Team request*/
                    AddUserToRecordTeamRequest addReq = new AddUserToRecordTeamRequest()
                    {
                        Record = entRef,
                        SystemUserId = loggedInUser,
                        TeamTemplateId = teamTemplate
                    };

                    requestWithResults.Requests.Add(addReq);
                    count++;
                    if (count == 999 || recordRemaining == 0)
                    {
                        ExecuteMultipleResponse responseWithResults = (ExecuteMultipleResponse)Xrmcontext.Execute(requestWithResults);
                        requestWithResults.Requests.Clear();
                        count = 1;
                    }
                }
            }
        }


To remove user from access team you can use RemoveUserFromRecordTeamRequest messge.

RemoveUserFromRecordTeamRequest addReq = new RemoveUserFromRecordTeamRequest()
    {
      Record = Record Entity Reference,,
      SystemUserId = User Id,
      TeamTemplateId = Access Team Template Id

    };

Use similar method as AddUserToAccessTeam, if you want to remove user from multiple records.