Pages Menu
TwitterRssFacebook

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

Learn Skype Web SDK Day 10 : Getting the Contact List

Learn Skype Web SDK Day 10 : Getting the Contact List

[contemplate-1]
View Demo

One of the things which the personsAndGroupsManager gives us is a full list of all contacts in the signed-in user’s contact list. This can be useful if you need to represent the contact list on screen, or want to use it for intelli-sense style searches.

The personsAndGroupsManager has a full list of both groups and users in a user’s contact list, however, neither will be populated unless you subscribe to the information. To do this, register an event listener for the .added function and then call subscribe(). The listener will be called for each person that’s added to the collection. For instance, to get a full list of users, this is how you would register the event listener for when users are added:

[code language=”javascript”]

Application.personsAndGroupsManager.all.persons.added(function (newUser) {
//do something with the new user here
});

[/code]
Once you have registered the listener, you can then call subscribe():

[code language=”javascript”]

Application.personsAndGroupsManager.all.persons.subscribe();

[/code]

You can use exactly the same approach to retrieve a list of groups, by using the groups object instead of the persons object:

[code language=”javascript”]

Application.personsAndGroupsManager.all.groups.added(function (newGroup) {
//do something with the new group here
});

Application.personsAndGroupsManager.all.groups.subscribe();

[/code]

In the code sample below, the user’s list of contacts and groups is displayed:

[code language=”javascript”]


Contact List:


    Group List:

      [/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]

      Post a Reply

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