码迷,mamicode.com
首页 > 其他好文 > 详细

crm SDK 设置用户的上级

时间:2017-03-09 20:56:16      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:users   muse   epc   nts   csdn   void   安全   name   ati   

        /// <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 设置用户的上级

标签:users   muse   epc   nts   csdn   void   安全   name   ati   

原文地址:http://www.cnblogs.com/BinBinGo/p/6527309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!