Onload client script to make field editable?

admin1
Kilo Contributor

I am trying to make cab field editable only when user is from some team 'abc' and has role admin then only can edit the cab field in change form and that will change the type  to normal and also approver will change accordingly....i have code but dont know the proper syntax.

function onLoad() {

if (g_user.is manager && g_user.hasRole('admin')) {

g_form.setDisplay('cab_required', true);// cab required field should be visible
var field = g_form.getValue('cab_required'); // if user ticks the field then type should get changed to normal and once its updated then the approvers will also change
if (field == true) {
g_form.setValue('u_type', 'u_normal', 'Normal');
}

}

challenges that am facing is am not able to check for users manager as they dont have role......please help me to achieve this

thanks in advance

 

5 REPLIES 5

Adrian Ubeda
Mega Sage
Mega Sage

Hi, 

If you want to make a field editable or not depending on role, better use an ACL than ClientScript. However, if you want to know if a user belongs to a group use as follows: gs.getUser().isMemberof();

Apart from that, I don't understand that part:
var field = g_form.getValue('cab_required'); // if user ticks the field then type should get changed to normal and once its updated
Cause you are basing the behaviour on a user action an should be managed as a ClientScript onChange instead of load.

If it was helpful, please give positive feedback.
Thanks, 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆