get user role in UI Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 01:37 PM
Hi, I'm trying to create a UI page that has certain fields readonly based on role. I have the following code in my client script, but I'm getting errors in my console saying gs is not defined and $(...).ready is not a function. Can someone help me debug this? Am I even on the right track?
var roles = [];
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID()) ;
gr.query();
while(gr.next()) {
roles.push({
role : gr.getDisplayValue('role') //Will give the sys_id of the roles
});
}
if (roles.indexOf('admin')) {
document.getElementById('signature').readonly = true;
document.getElementById('signature').style.backgroundColor = '#ddd';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 05:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 06:54 AM
Hi fred, thanks for helping me out. Sorry, how did you get the alerts from a UI Action? My code for the UI Page is below:
When I "Try It", I see this:
I have admin role so theoretically the HR Signature line should be grayed out and readonly, with dave in the input. The errors noted in my previous post are in my browser console. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 07:13 AM
Happy to help, and sorry if I'm not explaining things clearly.
I tested the "Try It" button in my personal developer instance and didn't get the alerts - I suspect that button only displays the HTML section but does not execute the client scripts. To get my alerts, I set up an UI action on the incident table just as a test. The code I'm using in my UI action is the following:
function test222() {
var dialog;
try {
dialog = new GlideModal('test222');
} catch(e) {
dialog = new GlideDialogWindow('test222');
}
dialog.setTitle('test');
dialog.setSize(750,300);
dialog.render();
}
}
This UI action is client callable and calls the test222() function onClick. Using the UI action then calls the UI Page and executes both the HTML and client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 07:17 AM
David Lu wrote:
certain fields readonly based on role.
Any reasons an ACL can't be used here? That's pretty much the standard solution to your problem definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 08:11 AM
Hey Dave, I looked into this briefly, but am a bit confused of how to apply ACL's on specific fields to specific UI Pages. Is there any material on this?
Below is the ACL page I see, but where would we define which UI Page this rule applies to? I assume if we have specific fields that need to be readonly depending on role, that would have to be scripted as advanced right?
Thanks.