Get details of current user in an iWidget


When building iWidgets for IBM Connections, you will likely want to obtain some details about the current user.  For example, you may want to retrieve the user’s display name for a greeting.  You might also be interested in the e-mail address or the IBM Connections unique ID for the user to make subsequent REST API calls.

You may retrieve the following attributes for the current user by obtaining the specific item from his/her profile:  displayName, email, userid

The iWidget API allows you to retrieve this information with a few simple lines of code.  For demonstration purposes, the following code will list all of the available keys, loop through the output, and add them to the root DOM node of the iWidget.

var attrNames = new Array("displayName", "email", "userid");
var root = this.iContext.getRootElement();
var list = dojo.create("ul", {}, root);
for (var x=0; x < attrNames.length; x++) {
   var val = this.iContext.getUserProfile().getItemValue(attrNames[x]);
   dojo.create("li", {"innerHTML": attrNames[x] + " = " + val}, list);

And here’s the result you would expect to see in your iWidget:

You can use these attributes to obtain user details and then pass them on to your third party systems to retrieve additional information. You can also choose to pass the IBM LtpaToken to your application for single sign-on purposes. If you do decide to connect to a third party service from your iWidget and pass data to it, you will first need to configure the AJAX Proxy.

You may also like...

2 Responses

  1. Nice blogentry. Is this only applicable for Profile or can it be used all over IBM Connections?

    • Paul says:

      Hi, Frank. You can use this code in your iWidgets. So, it’s limited to the areas of Connections that support iWidgets: Home Page, Profiles, and Communities. If you need Profile information elsewhere (for example, in a heavily customized UI), you can use the Profiles REST API to obtain details about the current user.

Leave a Reply