如何使用AngularJS在用户字段存储两个值?SharePoint任务多用户分配失败
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:
- First, collect both valid user IDs into an array.
- Assign that array directly to the
AssignedToproperty.
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.Caseownernameis a valid numeric SharePoint user ID. If it's a login name (likedomain\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
相关产品推荐
相关产品推荐

