- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 03:40 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 08:49 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 04:12 PM
Hi @Krissy ,
Try with below script:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 08:49 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 09:35 PM
@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
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 10:50 PM
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