Get all peoples using search (JSOM)

Hi,

I'm trying to get all users from share point Online using Search(JSOM).

when i tried with Content search web part(OOB), am getting 961 users. If I use the below code in sharpoint hosted app am getting only 350 users. Even My app has full control permission in Tenant Level.

var 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("2000");

                var properties = keywordQuery.get_selectProperties();

                properties.add("WorkEmail");

                properties.add("PreferredName");

                properties.add("JobTitle");

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

                var results = searchExecutor.executeQuery(keywordQuery);


Thanks,

July 15th, 2015 9:15am

Hi,

There's a limit to get max 500 in one call, so you need to page your calls to get everyone. Similar to what I do in this PowerShell script https://github.com/wobba/SPO-Trigger-Reindex/blob/master/reindex-users.ps1

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 9:21am

Hi Mikael,

Thanks for the reply, Is there any alternate option to get the all profiles in sharepoint online. I need to show all the users in sharepoint hosted app. Kindly suggest me the alternate option.

July 23rd, 2015 10:45am

Hi,

Using JSOM or REST in a SharePoint hosted to get all the profiles using search is probably the easiest approach.

What you need to do is put a loop around your existing code and do paging to retrieve all results. If you look at my PowerShell code you should easily see what happens and port it into your exising JSOM code (as it's written in CSOM more or less). 

Free Windows Admin Tool Kit Click here and download it now
July 25th, 2015 5:24am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics