Pages Menu
TwitterRssFacebook

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

Learn Skype Web SDK Day 8 : Setting Your Own Information

Learn Skype Web SDK Day 8 : Setting Your Own Information

[contemplate-1]
View Demo

As you know, it’s not just the presence information you can change in Lync. Some of the properties in the mePerson object can be set as well as read. These include the Location field and Note field – sometimes also called the Message of the Day – which is displayed at the top of the Lync client.

You can set these properties by passing the new value into them:


var me = client.personsAndGroupsManager.mePerson;
me.location("new location");
me.note.text("new note");

Note how the format for setting the note is slightly different. This is because it’s also used to store Out of Office notes. See the post of Getting Info for more information.

In this example, once logged in, the Note and Location information is displayed in text boxes, which can also be modified to update Lync. The maximum length of a Personal Note is 500 characters.

If you’re using the Lync client to see these changes, it’s best to log in as another user and then view the contact card of the user you are changing. If you sign in as the same user, you won’t see the Location field updated. This is because location (like presence) is aggregated. You might be signed into Lync in several places so Lync won’t automatically reset your location everywhere just because you set it in one place.

<div class="form-group">
<label for="username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="username" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-default" id="btnLogIn">Log in</button>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-default" id="btnLogOut">Log out</button>
</div>
</div>

<div>
<span id="loginStatus"></span>
</div>

<hr/>

<div class="form-group">
<label for="txtMOTD" class="col-sm-2 control-label">Note / MOTD</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="txtMOTD">
</div>
</div>

<div class="form-group">
<label for="txtLocation" class="col-sm-2 control-label">Location</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="txtLocation">
</div>
</div>

<script type="text/javascript">

var client;
$(function () {
'use strict';

Skype.initialize({
apiKey: 'SWX-BUILD-SDK',
}, function (api) {
client = new api.application();

// whenever client.state changes, display its value
client.signInManager.state.changed(function (state) {
$('#loginStatus').text("Login State: " + state);
});

}, function (err) {
alert('Error loading Skype Web SDK: ' + err);
});

$('#btnLogIn').click(function () {

// start signing in
client.signInManager.signIn({
username: $('#username').val(),
password: $('#password').val()
}).then(function () {
//log in worked!
alert('Logged in!');
GetOwnInfo();

}, function (error) {
//Something went wrong.
alert(error);
});
});

$('#btnLogOut').click(function () {
// start signing out
client.signInManager.signOut()
.then(function () {
//log out worked!
alert('Logged out!');
}, function (error) {
//Something went wrong.
alert(error);
});
});

function GetOwnInfo()
{
var me = client.personsAndGroupsManager.mePerson;

me.location.changed(function(newLocation) {
$('#txtLocation').val(newLocation);
});

me.note.text.changed(function(newNote) {
$('#txtMOTD').val(newNote);
});

}

$('#txtMOTD').on('change',function()
{
var me = client.personsAndGroupsManager.mePerson;
me.note.text(this.value);
});

$('#txtLocation').on('change',function()
{
var me = client.personsAndGroupsManager.mePerson;
me.location(this.value);
});

});

</script>

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]

Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.

Post a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.