Pages

Monday, September 20, 2010

Roles in XPages

I had a hard time working with user roles in XPages.

  I used to the following procedure which is a server script equivalent of the lotus script equivalent of the @UserRoles which wont work on server side javascript :) (confusing aaha...)

var acl:NotesACL= database.getACL();
var entry:NotesACLEntry = acl.getEntry(@Name("[CN]",@UserName()))
if (entry==null)    {
    entry = acl.getEntry(session.getUserName())
}
 
if (entry==null)    {
    return "";
}

entry.getRoles();


It did work to some extent. But I really had a very tough time with this. It seemed to work fine for a while but to my astonishment it started showing only my server's role enabled on the database . It was very irritating and I felt ridiculous about it.

Later I explored the web to arrive at the fairly simple decent solution as follows,

context.getUser().getRoles();

Yes the above mentioned line did the job for me. Hope this helps some one :)

6 comments:

  1. Welcome to the club! I ran into the same thing 2 weeks ago. There are some useful comments on my blog entry too

    http://www.bleedyellow.com/blogs/patpicos/entry/xpages_userroles_or_lack_of_and_name_fields_issue_displaying_names_data?lang=en

    ReplyDelete
  2. Went through the post. Good Stuff. Definetly @IsMember is better that context.getUser().getRoles().contains("[Role]");

    We can still take up Tim's suggestion of doing @UserRoles

    :)

    ReplyDelete
  3. I was unable to get the single context line to work. Everything came back as false.

    However using the ACL entry I was able to gain access to my roles.

    ReplyDelete
  4. Well, seems like some thing worked for you atlast. Should be a relief. Can you explain your problem a little more in detail so that I can possibly try and reproduce it. May be I can find a fix if I understand what is wrong

    ReplyDelete
  5. Have stumbled upon something more useful - http://ozinisle.blogspot.in/2013/11/roles-in-xpages-part.html

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete