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-22-2016 06:21 AM
Thanks Goran,
Thanks for the solution, it works. But I am wondering if I can work with the object directly without converting it to string. I hope any service now employee can help explain what type of object the getUserRoles() return or maybe point me to the API documentation of that function.
Thanks,
Kai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2016 07:35 AM
Hi Kai,
Why would you need that anyway ?
Regards,
Vikas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2016 09:30 AM
Hi vikas,
I am building a drop down menu in self service portal. AMD I store the menu item in navigation menu record. I use JavaScript to retrieve the menu item from the navigation menu record and try to filter it by the roles item in the record against the login user's role.
My approach is the following:
1. Get a list of the current login user's roles. (Call getuser().getuserroles()) Loop through them one by one.
2. Check each role against each menu item's role. If the roles in menu item record is empty, then always include the menu item.
3. If the roles item in the menu item record is not empty, then only include the menu item when the users role exists in the menu items roles item.
-Kai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2016 11:44 AM
can't you use the "hasRole" to check if the user has the menu items role?
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2016 12:07 PM
I can't do the reverse. Because I use query to retrieve the menu item record. AddQuery() and addorcondition(). I will post my final solution later.
-Kai