client script to hide form section

Krissy
Giga Guru

Hi

 

I am writing a client script to hide a section tab on the form if the user dosnt have a specific role. If they do have the role show it. My script is not working

 

function onLoad() {
    if (g_user.hasRole('training_bureau')) {
        g_form.setSectionDisplay('section_value', true);

        else if (!g_user.hasRole('training_bureau')) {
            g_form.setSectionDisplay('section_value', false);

        }


    }
 
am i missing anything?
1 ACCEPTED SOLUTION

Harish Bainsla
Kilo Patron
Kilo Patron

Hi use below code 

function onLoad() {
if (g_user.hasRole('training_bureau')) {
g_form.setSectionDisplay('section_value', true);
} else {
g_form.setSectionDisplay('section_value', false);
}
}

View solution in original post

4 REPLIES 4

Sumanth16
Kilo Patron

Hi @Krissy ,

 

Try with below script:

function onLoad() {
    if (g_user.hasRole('training_bureau')) {
        g_form.setSectionDisplay('section_value'true);

 

        else  {
            g_form.setSectionDisplay('section_value'false);

 

        }



    }
 
Approach 2:

Create UI policy with the following scripts:

update the UI policy script as this

Execute if true:

 

 

function onCondition(){

if(g_user.hasRole('training_bureau')){

g_form.setSectionDisplay('section_value', true);

}
else{

g_form.setSectionDisplay('section_value, false);

}

}

 

 

 

Note: expected behavior. g_form.setSectionDisplay('<form section name>', false), will check whether is there any fields are mandatory, before hiding it.

 

Before hiding the section in the client script, you have to make the fields in the section as g_form.setMandatory('field_name', false); for all the fields in the section and then you have to add g_form.setSectionDisplay('section name', false); it will work

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

Harish Bainsla
Kilo Patron
Kilo Patron

Hi use below code 

function onLoad() {
if (g_user.hasRole('training_bureau')) {
g_form.setSectionDisplay('section_value', true);
} else {
g_form.setSectionDisplay('section_value', false);
}
}

shyamkumar VK
Kilo Patron

@Krissy , The only Issue with your Script is your Validating the Role Multiple times and this can be simplified to below

if (g_user.hasRole('training_bureau')) { // this Validates if current user has role "Training Bureaue" 
g_form.setSectionDisplay('section_value', true);
} else {
g_form.setSectionDisplay('section_value', false);
}
}

 

Regards,

Shyamkumar

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Anwesha3
Mega Guru

hi @Krissy 
please use "else" in place of "if else"

Regards,
Anwesha
If this solution worked for you, please mark my answer as Accepted as Solution & Mark helpful