如何使用 SharePoint 客户端 API 获取所有用户配置文件? [英] How to get with SharePoint client APIs all user profiles?

查看:43
本文介绍了如何使用 SharePoint 客户端 API 获取所有用户配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了实施生日的 SharePoint 2013 应用程序,我需要从网站集中获取所有用户配置文件.为此,我想使用一个(或多个)客户端 API.请参阅 http://msdn.microsoft.com/en-us/library/jj163800.aspx#bkmk_APIversions.

不幸的是,我在 API 描述中找不到与 Microsoft.Office.Server.UserProfiles 等效的内容.Microsoft.SharePoint.Client.UserProfiles.PeopleManager 中有两种方法,GetUserProfilePropertiesForGetUserProfilePropertyFor,它们只能获取单个用户配置文件.>

所以我的问题是:如何使用 CSOM、JSOM、REST(或任何客户端技术)获取网站集中的所有用户配置文件?

解决方案

由于 CSOM 提供了与 per user 范围内的人员相关的操作方法,您可以首先使用 SP.Web.siteUsers 属性.然后使用SP.UserProfiles.PeopleManager.getUserProfilePropertyFor Method 获取BirthDay 属性如下所示:

//获取站点用户的生日用户配置文件属性函数 getUsersBirthdays(成功,错误){var clientContext = new SP.ClientContext.get_current();var web = clientContext.get_web();var users = web.get_siteUsers();clientContext.load(users);clientContext.executeQueryAsync(功能() {var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);var personProperties = [];for(var i = 0; i < users.get_count();i++){var user = users.getItemAtIndex(i);var personBirthday = peopleManager.getUserProfilePropertyFor(user.get_loginName(),'SPS-Birthday');peopleProperties.push(personBirthday);}clientContext.executeQueryAsync(功能() {成功(personsProperties);},错误);},错误);}//用法var scriptbase = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/';$.getScript(scriptbase + 'SP.js', function () {$.getScript(scriptbase + 'SP.UserProfiles.js', function () {getUsersBirthdays(function(usersProperties){for(var i = 0; i < usersProperties.length;i++){console.log(usersProperties[i].get_value());}},功能(发件人,参数){console.log(args.get_message());});});});

For implementing a birthday's SharePoint 2013 app I need to get all user profiles from a site collection. For this purpose I'd like to use a (or multiple) client API(s). See http://msdn.microsoft.com/en-us/library/jj163800.aspx#bkmk_APIversions.

Unfortunately I couldn't find in the APIs description an equivalent of Microsoft.Office.Server.UserProfiles. There are in Microsoft.SharePoint.Client.UserProfiles.PeopleManager two methods, GetUserProfilePropertiesFor and GetUserProfilePropertyFor, that only get a single user profile.

So my question is: how to get with CSOM, JSOM, REST (or any client side technology) all user profiles in site collection?

解决方案

Since CSOM provides methods for operations related to people per user scope, you could retrieve all site users first using SP.Web.siteUsers property. and then use SP.UserProfiles.PeopleManager.getUserProfilePropertyFor Method to get BirthDay property as demonstrated below:

//Get Birthday User Profile Property for Site Users 
function getUsersBirthdays(Success,Error) {
    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web(); 

    var users = web.get_siteUsers();
    clientContext.load(users);
    clientContext.executeQueryAsync(
    function() {
       var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
       var personsProperties = [];
       for(var i = 0; i < users.get_count();i++)
       {
           var user = users.getItemAtIndex(i);
           var personBirthday = peopleManager.getUserProfilePropertyFor(user.get_loginName(),'SPS-Birthday');
           personsProperties.push(personBirthday);
       }

       clientContext.executeQueryAsync(
           function() {
             Success(personsProperties);
           },
           Error);

    },
    Error);



}



//Usage
var scriptbase = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/';
$.getScript(scriptbase + 'SP.js', function () {
  $.getScript(scriptbase + 'SP.UserProfiles.js', function () {
    getUsersBirthdays(function(usersProperties){
       for(var i = 0; i < usersProperties.length;i++)
       {
           console.log(usersProperties[i].get_value());
       }
    },
    function(sender,args){
       console.log(args.get_message());
    });
  });
});  

这篇关于如何使用 SharePoint 客户端 API 获取所有用户配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆