Hi Team,
I am populating people picker in SharePoint Online using Angular and Jquery. My issue is not all users present in the Tenant are populating in the PeoplePicker.
Can someone please correct this to get all users present in the Tenant.
Below is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Angular PP</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://code.angularjs.org/1.3.0/angular.js"></script>
</head>
<body ng-app="myApp" ng-controller="MainCtrl">
<label for="tags">Assigned To: </label>
<input id="Persons" ng-model="SelectedPerson"/><br/><br/>
<input type="button" ng-click="AddToList()" value="Submit"/>
</body>
<script type="text/javascript">
var app = angular.module('myApp', []);
var peoplePickerUsers =[];
var AllpeoplePickerUsers =[];
var CurPersonId
var listName ="AngularPP";
app.controller('MainCtrl',function($scope,$http) {
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers",
type: "GET",
headers:
{
"Accept": "application/json;odata=verbose"
},
success: function(data)
{
AllpeoplePickerUsers = data.d.results;
console.log(AllpeoplePickerUsers);
for (var i = 0; i < AllpeoplePickerUsers.length; i++) {
var property = AllpeoplePickerUsers[i].Title;
peoplePickerUsers.push(property);
}
},
error: function(error)
{
alert(JSON.stringify(error));
}
});
$( function() {
$( "#Persons" ).autocomplete({
source: peoplePickerUsers
});
} );
$scope.AddToList=function(){
for(var i=0;i<AllpeoplePickerUsers.length;i++){
if ($scope.SelectedPerson=== AllpeoplePickerUsers[i].Title)
{
CurPersonId=AllpeoplePickerUsers[i].Id;
}
}
var datavalue = "{__metadata:{'type':'SP.Data."+listName+"ListItem'},AssigningToId:'"+CurPersonId+"'}";
// alert(datavalue);
$http({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('"+listName+"')/items",
method: "POST",
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "POST"
},
data: datavalue
})
.then(function(response) {
alert("success");
},
function(response) {
alert("failed");
});
}
});
</script>
</html>
Ganesh