Archive for March 28, 2012

Get User Information from Client OM (JS)

When I was exploring the possibilities to read from a User Profile in a SharePoint Online environment I realized there are lots of properties that are being synced back to the UserInfoList, but only when they are filled in the User Profile.

User Info List

We know by now it’s impossible from a Sandboxed Solution (or Client Side OM Solution) to access a Users Profile directly as you would in a On-Premise environment. Our scope is the SiteCollection that runs our custom code. In that scope there is one important resource we can use to get information about a User, the UserInfoList. The list contains some Properties that are populated by the SharePoint Profile. So somehow this is synced.

Synced Properties

The synchronization process is done (On-Premise) by a TimerJob called: “User Profile Service Application – User Profile to SharePoint Full Synchronization”. This TimerJob normally runs “Hourly”. I didn’t test this out but my guess is that this will be the case with SharePoint Online too. The important part being that there is a delay in this procedure. That being said, which properties of the User Profile are being synced by this TimerJob?

Property StaticName (Client OM) Returns
Account name Name domain\ierselca or claim
User name UserName ierselca
Name (DisplayName) Title Cas van Iersel
First name FirstName Cas
Last name LastName van Iersel
Title JobTitle SP Consultant
Email EMail
Work phone WorkPhone 0123456789
Mobile phone MobilePhone 0123456789
Picture Picture http://linktoimage *
Department Department R&D
About me Notes Inner HTML of About field as a string
Web site WebSite *
SIP SipAddress sip format string
Office Office Rapid Circle
Ask me about SPSResponsibility SharePoint, C#, ASP
If User Is Site Admin IsSiteAdmin true | false

* You’ll need to do .get_url() on the return object

This is an example on how to get the information based on the UserID in the Context of the current web (You can obtain this from the SPUser object or use javascript to get from a people link “person.aspx?ID={UserID}”:

    //Get the Context, Web and SiteUserInfoList for User Info
    var clientContext = SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var collListItem = web.get_siteUserInfoList().getItemById(userID);

        //Load the objects async
    Function.createDelegate(this, function(){
          //Read all properties from the Item
                 var userName = collListItem.get_item(‘Name’);
                 var website = collListItem.get_item(‘WebSite’).get_url();
     }), Function.createDelegate(this, function(){
         //On Fail

Note: When the field is empty in your profile the get_item() Method will return null on the property.

Profile Picture

On property that can be slightly inconvenient is the Profile Picture. The URL is stored in the UserInfoList so that will be returned perfectly. But with SharePoint Online the Picture is most definitely stored in the MySite Host webapp. This means the user is challenged for credentials when this URL is used in an <img /> tag for instance.


There is a lot of User Information we can work with using the Client OM. It’s very easy to obtain the information using Javascript and to do cool stuff with it. Just keep in mind that the syncing process can take some time and no custom properties are being synced.

Inconvenient (Sandboxed) Custom ListDefinitions

Building custom SharePoint Online solution a List Definition is likely to be a SPI you would like to use. Sandboxed Solution look like a good way of deploying these definitions to your SharePoint Online environment, but are they?

When we deployed custom List Definitions we came across strange behavior accessing these lists. Suddenly the language changed from Dutch (nl-NL) to the default language (en-EN). Together with the help of MS we found some interesting information in the Logs. SharePoint was trying to access a resource file we didn’t deploy.

Localized Strings
A SharePoint Feature comes with the property DefaultResourceFile. This property can be set with the Feature Properties. When empty SharePoint will try to get the resource from “%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATES\FEATURES\FeatureName\Resources\Resources. Culture.resx” when a resource is requested by a Localized string. When you create a ListDefinition in Visual Studio the Schema.xml is being generated for you. The <List /> element contains an Attribute called Direction which is a localized string. Direction=”$Resources:Direction;”

The Localized string doesn’t refer to a default Resource file but instead it tries to get the Resource from the DefaultResourceFile. This results in an error when you are not deploying a Resource File to this location containing “Direction”.

This blogpost states that with SP1 the problem is resolved. However together with MS we found out that the error in the Log files still occurs in SharePoint Online. The easiest way to fix this is to replace the localized string in your schema.xml for a hardcoded value. MSDN explains what values can be used (

If you don’t want to choose this option for some reason, according to MS you can also choose to reference the Core Resource file Direction=”$Resources:core,Direction;”. This didn’t give me the error on premise, but obviously I couldn’t test it in Office 365 because I’m not able to check the Log files. I didn’t experience the language change as before so I assume this is a good option. Still the value in the core resource file for Direction is 0 which is not given as an option according to MSDN. My guess is that SharePoint sees this as “none”.