getRoles() for user object - how does it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2012 12:25 PM
I can't seem to find any info on the getRoles function. The wiki says that it returns all of the roles of the current user and gives an example:
var myUserObject = gs.getUser();
myUserObject.getRoles() returns all of the roles of the current user
I'm trying to access those return values (I'm assuming it's an array or strings?) but I can't get it to show anything.
I'm probably just not seeing the obvious.....
Has anyone used this to return all the roles of the current user object? I'm actually using it in a debug statement but nothing prints when I do
gs.log("current user's roles=" + myUserObject.getRoles().toString());
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2012 01:52 PM
there is a pretty good example of it on the wicki a little further down.. you have to define and load it into an array....
when i needed it i only needed to know if they had a set role.. so instead i used the hasrole method...
var ouruser = gs.getUser();
if
(ouruser.hasRole('itil'))
_________________________________
the example from the wiki is below
http://wiki.servicenow.com/index.php?title=Getting_a_User_Object
function returnCurrentUserGroup(){
var myUserObject = gs.getUser();
var myUserGroups = myUserObject.getMyGroups();
var groupsArray = new Array();
var it = myUserGroups.iterator();
var i=0;
while(it.hasNext()){
var myGroup = it.next();
groupsArray=myGroup;
i++;
}
return groupsArray;
}
var test = returnCurrentUserGroup();
gs.print(test[0]);