how to make a field read only based on Logged in user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 08:01 AM
I have a Field on my form and I want ti make that field READONLY based on Logged in user.
It should be editable to only 4 users.
I have tried scripting in UI Policy and Onload Client Script, But both are not working.
UI Policy Script:
if(g_user.userName != 'username' || g_user.userName != 'username'){
g_form.setReadOnly('fieldname', true);
Onload SCript:
function onLoad() {
//Type appropriate comment here, and begin script below
alert('the current Logged in user is '+g_user.userName);
var ga = g_user.userName;
if(ga != 'username' || ga != 'username'){
g_form.setReadOnly('field name', true);
}
}
I had imperonated the user and user and checked but it is readonly for him too..
I dont know where i am going Wrong. Can anyone please help.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 08:14 AM
you should be able to use something like this:
an onLoad client script
if (gs.getUser().isMemberOf('<user group>')){
g_form.setReadOnly('<field_name>', true);
}
OR
a Scripted UI Policy
function onCondition() {
var notAllowedToEdit = g_user.hasRole('change_manager');
if(allowedToEdit)
{
g_form.setReadOnly('<field_name>', true);
}}
Hope you can use this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 08:20 AM
Hi Dave,
We cannot use gs. on client side right ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 08:25 AM
yeah, you can use jslog and open up the Javascript log and field watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 08:27 AM
Ideally, you should consider using g_user.hasRole() but anyways if you have decided on specific user names still it should work. I used below sample script and it works for me:
function onCondition() {
if(g_user.userName == 'userName');{
g_form.setReadOnly('field_name', true);
}
}