How to traverse user role from getUserRoles() function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2016 01:14 PM
I am getting userRoles from:
var thisUser = gs.getUser();
var userRoles = thisUser.getUserRoles();
//var userRoles2 = thisUser.getRoles(); //this doesn't really work, because when I turn debug log on, and call gs.print(userRoles2); it only return one role.
gs.print(userRoles); //this return 2 roles.
Now I would like to traverse the role, but no matter what I try, i failed.
//gs.print(userRoles.length); failed, maybe because userRoles is not an array?
//for (role in userRoles){gs.print(role)}; failed, again because userRoles is not an array.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2016 01:45 PM
Try this:
var thisUser = gs.getUser();
var myArray = thisUser.getUserRoles().toString().split(",");
for (i=0; i<myArray.length;i++) {
gs.log(myArray[i]);
}
One thing that I can't explain is that getRoles() returns more roles than getUserRoles(). No idea why.
Perhaps something you know kalai ?
//Göran

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2016 10:23 PM
getRoles() - Gives all the roles that the user has.
getUserRoles() - Gives only the roles that were manually assigned to the user (not inherited from any roles or groups)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2016 06:19 AM
Hi Kalaiarasan,
Where did you find the API? I couldn't find any documentation explaining what type of object it's returning.
And for some reason, I get more role from getUserRoles() than getRoles().
Thanks,
Kai

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2016 01:30 AM