Search User

搜索用户

var users = [];
var userProfileProperties = [];
function getAllUsers(searchTerm) {
    clientContext = new SP.ClientContext.get_current();
    //Building Keyword query for the search
    var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext);
    keywordQuery.set_queryText(searchTerm);
    keywordQuery.set_sourceId("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
    keywordQuery.set_rowLimit(500);
    keywordQuery.set_trimDuplicates(false);

    var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);
    results = searchExecutor.executeQuery(keywordQuery);

    clientContext.executeQueryAsync(onQuerySuccess, onQueryError);
}
function onQuerySuccess() {
   $.each(results.m_value.ResultTables[0].ResultRows, function () {
        users.push(this.AccountName);
    });
    fetchProfilePropertiesForUsers(); 
}

function fetchProfilePropertiesForUsers() {
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
    var profilePropertyNames = ["PreferredName", "PictureURL", "AboutMe", "TechNetProfile", "AccountName","Manager"];
    for (var i = 0; i < users.length; i++) {
        var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(clientContext, users[i], profilePropertyNames);
        userProfileProperties[i] = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);
    }
    clientContext.executeQueryAsync(onSuccess, onQueryError);
}

function onSuccess() {
    console.log(userProfileProperties);
}
function onQueryError(sender, args) {
    alert(args.get_message());
}

猜你喜欢

转载自www.cnblogs.com/jackhu88/p/9210133.html