Pages Menu
TwitterRssFacebook

Posted by on May 14, 2015 in Learn Skype Web SDK

Learn Skype Web SDK Day 11 : Searching for Users & Groups

Learn Skype Web SDK Day 11 : Searching for Users & Groups

[contemplate-1]
View Demo

The Skype for Web API provides a means for you to query a user’s contact list for specific contacts or groups, rather than requiring you to download the entire list and then parse it on the front-end. This means that your application can select individual contacts much easier. For instance, if you’re writing an application in which you want to display the presence information of a specific contact (either hard-coded, stored in a database, or entered by the user at run-time) you can pick out just that single contact and subscribe to their presence.

Searching for contacts and groups is very similar. Both searches require you to specify a maximum number of return records, and a simple text search term, which can be the full or part name of a contact or group. And they both return their results in an async promise function, getMore().

Both searches are instantiated via the personsAndGroupsManager object. To create a contact query, create the search object with:

[code language=”javascript”]

var contactSearch = application.personsAndGroupsManager.createPersonSearchQuery();

[/code]

for groups it’s:

[code language=”javascript”]

var groupSearch = application.personsAndGroupsManager.createGroupSearchQuery();

[/code]

Both of these functions will only work once you’ve completed the login process.

To set up the return limit and search text, for both objects it’s the same (using contact search in these examples, but swap the contactSearch object for groupSearch for a group search):

[code language=”javascript”]

contactSearch.limit(10); //only return 10 results
contactSearch.text(‘bob’) //the search term

[/code]

To actually execute the search, call getMore and then access the results in the return method:

[code language=”javascript”]

contactSearch.getMore(function (searchResults) {
searchResults.forEach(function (item) {
var contact = item.result; //for contacts
var group = item.result; //for groups;
});
});

[/code]

The code sample shows this in action:

[code language=”javascript”]


Search Results:

    [/code]

    Demo Online

    You can try this code out against your own Skype for Business environment by going to the demo page. From here you can also download the code from GitHub if you want to host it locally, or take it and use it in your next project.
    [contemplate-2]

    1 Comment

    1. Hi,

      I was just fiddling around with your examples, and found it strange that when searching for groups the address of the request was still /people/search? etc..

      Do you now if this is a bug in the SDK? I can’t seem to access distribution groups through the SDK, I understand that this should be possible through UCWA, and thought that this may be the problem.

    Post a Reply

    Your email address will not be published. Required fields are marked *