Pages

Monday, September 20, 2010

Getting User's Name on the XPage

The content that I am trying to describe on this particular post is fairly simple. Many of you guys out there would have faced it and solved it. But still I would like to share this cos, really XPages are stupid at times.

I had the formula session.getCommonUserName() on a lable which worked for me through out the period I was developing my last application. When I moved the same to a test server to test the same, to my astonishment I found that the label with the above mentioned code displaying my test server's name.

I opened up the XPage in designer, saved it manually,
Signed the database using server id,
compacted the database ,
Restarted my test server etc etc...

All of the above steps failed and it still kept displaying my server name

Later I changed the code to @Name("[CN]",@UserName()), the formula eqivalent in server script.
OOPS that failed tooo...

And after a few brief moments of frustrations, I got the following idea,
@Name("[CN]",session.getEffectiveUserName())

And that eventually saved me.

Feels strange aaha...

Hope this helps :)

6 comments:

  1. The same DirectoryUser object you used to retrieve the user's roles has methods to retrieve their name; unfortunately, there's a bug with the getCommonName method, causing it to return the same value as getDistinguishedName. So here's an alternate approach to determining the current user's common name:

    @Name("[CN]",context.getUser().getDistinguishedName())

    ReplyDelete
  2. Thanks Tim. Hope we get the good documentations for XPages with 8.5.2

    ReplyDelete
  3. Thanks karthikeyan ! your tip saved me time :) !

    ReplyDelete
  4. thank you for sharing this, I was getting the exact error on browser.

    ReplyDelete