標籤:crm設定使用者上級和業務部門 crm刪除使用者的上級 crm設定使用者的業務部門 crm設定使用者的上級
/// <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);
}