How to show field for particular user?

Sid_Takali
Kilo Patron
Kilo Patron

Hi Team,

If we have a field 'Security number' for each user , what will be your approach for making it visible only for that particular user?

1 ACCEPTED SOLUTION

Peter Bodelier
Giga Sage

Hi @Sid_Takali,

 

I guess that security number is stored on the sys_user record?

If so, create a field level read ACL restricted to the logged in user for that record.

 

So, ACL: sys_user.u_security_number (Or your field name), Read with script:

answer = current.getUniqueValue() == gs.getUserID();


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi @Sid_Takali ,

I would add a role to that group and then use a client script to display/hide that field based on whether the current logged in user has that role.

Below is an example on how to do that;



function onLoad() {

var isAdmin = g_user.hasRole('admin');
//console.log("isAdmin: " + isadmin);
if (isAdmin == true) {
g_form.setDisplay('staff_type', 'true');
} else {
g_form.setDisplay('staff_type', 'false');
}
}

Peter Bodelier
Giga Sage

Hi @Sid_Takali,

 

I guess that security number is stored on the sys_user record?

If so, create a field level read ACL restricted to the logged in user for that record.

 

So, ACL: sys_user.u_security_number (Or your field name), Read with script:

answer = current.getUniqueValue() == gs.getUserID();


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Mohith Devatte
Tera Sage
Tera Sage

Hello @Sid_Takali ,

It depends on the requirement 

 

if its for a group of users, add them into a group and  you can create a field level ACL and check if logged in user is part of the group then make it visible using the below advanced script in ACL.

answer = gs.getUser().isMember0f('your_group_name');

 

IF ITS FOR A SINGLE USER the value will be static and you can simply create a UI policy where condition can be user is abel tuter , some thing like this and create a UI policy action to hide the security number filed 

 

if its for bulk users who has got a particular role then you can check it via client script that if logged in user is having that role and if yes display the field using on load client script like below 

function onLoad() {

    var usrRole = g_user.hasRole('your_role_name');

    if (usrRole == true) {
        g_form.setDisplay('your_field_name', 'true');
    } else {
        g_form.setDisplay('your_field_name', 'false');
    }
}

Hope this helps 

Mark my answer correct if this helps you 

Thanks

 

 

Hi @Mohith Devatte,

 

Good that you are providing different scenarios, but since the field is a security number I would never do anything else than an ACL.

 

UI Policies and Client Scripts can be easily overridden by disabling javascript or manipulating the html in your browser.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.