- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 04:48 PM
Hello all,
I understand that UI scripts are not *recommended* at this point, however, for what I need to accomplish I believe it's the only way to get it done.
Basically, I need to detect a user's groups in a UI script and hide certain elements on any given page based on the user's groups. These elements are html objects contained within content blocks. Therefore, attaching roles to content blocks will not accomplish what I need to.
It appears that in my UI script the g_user object is not yet defined. Even when calling getActiveUser() it doesn't appear to create the object. g_user.userID returns undefined at that point.
The end goal is for me to be able to call g_user.hasRole() - or at the very least query sys_user_grmember using g_user.userID. I am aware of the possible overhead here, however, I feel like user object/data should be baseline available to us even when using deprecated UI scripts.
Is there any workaround for this issue? I am running Eureka.
Thanks
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 06:01 PM
Ok, tested this in a demo instance...
UI Script
userHasRole('admin');
function userHasRole(role){
var ga = new GlideAjax('CheckUserRole');
ga.addParam('sysparm_name','u_hasRole');
ga.addParam('sysparm_role',role);
ga.getXMLWait();
alert(ga.getAnswer());
}
Script Include
Name: CheckUserRole
Client Callable: Checked
var CheckUserRole = Class.create();
CheckUserRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
u_hasRole: function() {
var role = this.getParameter("sysparm_role");
return gs.hasRole(role);
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2021 11:41 PM
Hey Scott,
window.NOW.user.roles doesn't work in portal, any guidance?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2021 12:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2021 03:55 PM
You can use top.window.NOW object which has many different useful attribute as below:
top.window.NOW.instance_name
top.window.NOW.page_id
top.window.NOW.portal_id
top.window.NOW.portal_url_suffix
top.window.NOW.user_display_name
top.window.NOW.user_id
top.window.NOW.user_id_hashed
top.window.NOW.user_impersonating
top.window.NOW.user_initials
top.window.NOW.user_name
Cheers
Syed.