首页 > 代码库 > crm SDK 设置用户的上级

crm SDK 设置用户的上级

        /// <summary>        /// 设置用户的上级        /// </summary>        /// <param name="service">服务</param>        /// <param name="userId">用户</param>        /// <param name="parentId">上级</param>        public void SetUserParent(IOrganizationService service, Guid userId, Guid parentId)        {            SetParentSystemUserRequest request = new SetParentSystemUserRequest();            //当前用户            request.UserId = userId;            //上级            request.ParentId = parentId;            //是否保存子用户            request.KeepChildUsers = true;            service.Execute(request);        }

背景: crm 从旧系统重新迁移到新系统. 

以上代码可以随便放在一个plugin里执行就行了.

 

 

 

引自:http://blog.csdn.net/y_f123/article/details/37870313

 

/// <summary>        /// 删除用户的上级        /// </summary>         public void RemoveParent(IOrganizationService service,Guid userId)         {            RemoveParentRequest removeRequest = new RemoveParentRequest();            removeRequest.Target = new EntityReference() { LogicalName = "systemuser", Id = userId };            service.Execute(removeRequest);        }        /// <summary>        /// 设置用户的业务部门        /// </summary>        /// <param name="service">服务</param>        /// <param name="userId">用户Id</param>        /// <param name="businessId">部门Id</param>        public void SetUserBusiness(IOrganizationService service, Guid userId,Guid businessId)         {            //更改用户的业务部门,会重置角色            SetBusinessSystemUserRequest request = new SetBusinessSystemUserRequest();            request.BusinessId = businessId;            request.UserId = userId;            //安全角色            request.ReassignPrincipal = new EntityReference() { LogicalName = "role",Id = Guid.NewGuid() };            service.Execute(request);        }        /// <summary>        /// 设置用户的上级        /// </summary>        /// <param name="service">服务</param>        /// <param name="userId">用户</param>        /// <param name="parentId">上级</param>        public void SetUserParent(IOrganizationService service,Guid userId,Guid parentId)         {            SetParentSystemUserRequest request = new SetParentSystemUserRequest();            //当前用户            request.UserId = userId;            //上级            request.ParentId = parentId;            //是否保存子用户            request.KeepChildUsers = true;            service.Execute(request);         }

 

crm SDK 设置用户的上级