/// <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设置用户上级和业务部门