清理 CRM 中的访问团队记录

Cleaning an Access Team Record in CRM

我必须clean/to清空基于访问团队模板的访问团队记录。

如何一次性删除访问团队记录中的所有用户?或获取用户列表,然后为每个用户调用 RemoveUserFromRecordTeamRequest()

解决方法如下:

 internal void CleanAccessTeam(IVisibilityService service, Guid recordId)
    {
        QueryExpression query = new QueryExpression(CrmTeam.EntityLogicalName);
        FilterExpression filter = new FilterExpression();
        filter.Conditions.Add(new ConditionExpression(CrmTeam.Lookups.RegardingObjectId, ConditionOperator.Equal, recordId));
        query.Criteria.AddFilter(filter);
        var teams = service.RetrieveMultipleRecord(query);
        if (teams.Entities.Count > 0)
        {
            service.Delete(CrmTeam.EntityLogicalName, teams.Entities[0].Id);
        }
    }