You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用AngularJS在用户字段存储两个值?SharePoint任务多用户分配失败

Fixing Multi-User Assignment for SharePoint Tasks

I see the issue here—your current code uses the && operator for the AssignedTo field, which only returns the second value if the first is truthy. That's why only one user is getting assigned. SharePoint's multi-user AssignedTo field expects an array of user IDs (or user objects) instead of a single value.

Here's how to fix it:

  1. First, collect both valid user IDs into an array.
  2. Assign that array directly to the AssignedTo property.

Modified Code:

$scope.createTask = function() { 
    var item = $scope.taskDetails; 
    var taskcase = $scope.caseDetails; 

    // Collect valid assignee IDs into an array
    var assignees = [];
    if (_spPageContextInfo.userId) {
        assignees.push(_spPageContextInfo.userId);
    }
    if (taskcase.Caseownername) { // Ensure this is a valid SharePoint user ID
        assignees.push(taskcase.Caseownername);
    }

    var updates = angular.extend({}, { 
        Title: item.Title, 
        DueDate: item.DueDate ? moment(item.DueDate, 'DD/MM/YYYY').format() : null, 
        Status: item.Status, 
        AssignedTo: assignees, // Use the array for multiple assignees
        RelatedCase: $routeParams.id 
    }); 

    ModalDialog.showWaitScreen({ message: 'Creating task for case ' + updates.Title }).then(function (waitScreen) { 
        return CaseManagementService.createTask({ updates: updates }).then(function (task) { 
            $log.info('task created', task); 
            $scope.taskDetails = { Status: 'Not Started' }; 
            $scope.loadRelatedTasks(); 
            return ModalDialog.delayClose(waitScreen, 200); 
        }, function(e){ 
            console.error(e); 
        }); 
    }); 
};

Important Notes:

  • Double-check that taskcase.Caseownername is a valid numeric SharePoint user ID. If it's a login name (like domain\username) or display name, you'll need to convert it to a user ID first using the SharePoint Client Object Model or REST API.
  • If either user ID might be missing or invalid, the array will automatically only include valid entries, keeping your code robust.

内容的提问来源于stack exchange,提问作者Al Roome

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 09:23:12