Hide field based on state and role of user

VSN
Tera Expert

Hi,

I have a requirement, if state is draft and user contain csd_admin, csd_user roles then i have to make Program field Visible.

4 REPLIES 4

Prince Arora
Tera Sage

@VSN 

 

Please write a onload client script and mention the code as follows:

 

if(g_form.getValue("state")== 1 && g_user.hasRole("csd_admin") ||  g_user.hasRole("csd_user") ){ //check the backend 
value of draft

g_form.setDisplay("program", "true"); // please check the backend name of program and mention here

}else{

g_form.setDisplay("program","false"); //here too..

}

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.
 

Steven Parker
Giga Sage

You can use a UI Policy where State is Draft and then use the Script section (Execute if True section) of it to check for roles like the following:

 

 

function onCondition() {

if(g_user.hasRoleExactly('csd_admin') || g_user.hasRoleExactly('csd_user')) {
	g_form.setVisible('<name_of_field>', true);
}

}

 

 

 

 

 


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

this conditions are applying to the admin also. but i need to hide that fields only for the particular role users

Jyoti Jadhav9
Tera Guru

Hi @VSN,

 

You can use a UI Policy where State is Draft and then use the Script section (Execute if True section) of it to check for roles like the following:

Execute if True section:

function onCondition() { 
if((g_user.hasRoleFromList('csd_user','csd_admin') && !g_user.hasRoleExactly('admin')) || (g_user.hasRoleExactly('admin'))){
        g_form.setDisplay('program',true);
    }
    else{
        g_form.setDisplay('program',false);
    }
}

Execute if False section:

function onCondition() {
if(g_user.hasRoleFromList('csd_user','csd_admin') && !g_user.hasRoleExactly('admin')){
g_form.setDisplay('program',false);
}
}

 

Please mark reply as Helpful/Correct/Accept Solution, if applicable. Thanks!

 

Thanks & Regards

Jyoti Jadhav