How to access list of website users from SharePoint hosted app?
-
01-10-2020 - |
Frage
My app is hosted here:
https://mySite.sharepoint.com/sites/path/myApp/
And user information is hosted here:
https://mySite.sharepoint.com/sites/path/_catalogs/users/simple.aspx
I already use this code to access lists outside of my app
function getLists() {
print("retrieving list");
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
currentcontext = new SP.ClientContext.get_current();
hostcontext = new SP.AppContextSite(currentcontext, hostUrl);
web = hostcontext.get_web(); // hostcontext instead of currentcontext
listCollection = web.get_lists();
list = listCollection.getByTitle(LIST_NAME);
listItemCollection = list.getItems(""); // use CAML query for specific requests
context.load(listItemCollection);
context.executeQueryAsync(sharePointReady, queryFailed);
}
How can I adjust this code to get a list of all the users in my website like their name and contact information? Or is there another method?
Thanks in advance.
Lösung
REST
/_api/Web/SiteUsers
JSOM
var ctx = SP.ClientContext.get_current();
var users = ctx.get_web().get_siteUsers();
ctx.load(users);
ctx.executeQueryAsync(function() {
var userArray = [];
var e = users.getEnumerator();
while (e.moveNext()) {
userArray.push(e.get_current());
}
console.log(userArray);
});
Andere Tipps
In this case list = listCollection.getByTitle(LIST_NAME);
would become list = listCollection.getByTitle("UserInformationList");
or list = listCollection.getByTitle("User Information List");
.
That is the underlying list where the users are stored.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange