Hi All,
In this blog, we will see how to fetch user profile properties of all users from SharePoint online.
Many times we need to display specific properties of all users programmatically, so for that, I have Rest API to access User profiles properties. In this case, if properties are mapped to an Active directory then the available data is correct and dynamic.
First we need to add jQuery reference in our file
- <script src="/SiteAssets/JS/jquery.min.js"></script>
SiteUsers is used to get all the users of SharePoint Online site.
- <script>
- $.ajax({
- asynch: false,
- url: "your site url /_api/Web/SiteUsers",
- method: "GET",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- for (var i = 0; i < data.d.results.length; i++) {
- var accountName = data.d.results[i].LoginName;
- GetUserProperties(accountName.replace("#", "%23"));
- }
- }
- },
- error: function(x, y, z) {
- alert(JSON.stringify(x) + '\n' + JSON.stringify(y) + '\n' + JSON.stringify(z));
- }
- });
GetUserProperties function is used to get the user profile properties of specific users in SharePoint site.
- function GetUserProperties(user) {
- $.ajax({
- asynch: false,
- url: "your site name/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + user + "'",
- method: "GET",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data) {
- console.log("Name = " + data.d.DisplayName);
-
- console.log("-------------------");
- },
- error: function(data1) {
- alert("ERROR");
- }
- });
- } < /script>
Thank You..
| | | | | | | | | |
Text-to-speech function is limited to 200 characters