Hide section using setSectionDisplay to false failed?

praveenKumar2
Kilo Expert

Hi Developers,

I have written the below script to hide a section with the following code:

function onLoad() {

var sections = g_form.getSectionNames();

if (g_user.isMemberOf('CAB Approval')){

g_form.setSectionDisplay('related_records',true);

}else{

g_form.setSectionDisplay('related_records',false);

}

}

Turns out this script doesn't get executed. Can i know the reason why? when i used g_user.hasRole('inc_viewer'); it worked.

Let me know if i am missing something here...

Thanks,

pK.

1 ACCEPTED SOLUTION

Hi Shloke,

 

I tried this but didn't work, I did a small tuning because I created a form section called "Employee Location" that I want to hide from a group "HR On Boarding". This is the script I used (I did the display BR as you suggested and called it on the script):

function onLoad() {
var sections = g_form.getSectionNames();
if (g_scratchpad.grp == 'true')
{
g_form.setSectionDisplay('Employee Location',false);
}
else{
g_form.setSectionDisplay('Employee Location',true);
}
}

 

Please let me know your thoughts.

Regards Danny

View solution in original post

7 REPLIES 7

nthumma
Giga Guru

isMemberOf('CAB Approval') method only works on server-side.



please check below thread


isMemberOf function in client script


Rama Chandra D
Kilo Guru

Hi Praveen,



Use a display business rule to check for the membership condition. Store the boolean result in g_scratchpad. And use the g_scratchpad variable in your onLoad client script.



Darshak


Harsh Vardhan
Giga Patron

Hi Praveen,



isMemberOf() works at server side. and you had mentioned in client script that's why it will not work.


if you want to use then you must need to use "Glide Ajax" or you can also try with Display Business Rule.


but display business rule will never work on OnChange() you must need to reload the page then it will work.



if you will use onLoad() client Script then display business rule will work perfectly if you will try with glide ajax then in both scenario it will work .


shloke04
Kilo Patron

Hi,



As mentioned by others above, "ismemberOf()" is a Server Side function and won't work on Client Side. in order to check whether the current Logged in User is a Member of the mentioned Group( "CAB Approval"), you need to use a Display Business Rule and store the Value in a Scratchpad Variable. Once stored you can pass that Scratchpad Variable to the client Side and have your Validations as desired.



For Reference please follow the below steps:



1) Create a Display BR as shown below on the Required Table:



g_scratchpad.grp = gs.getUser().isMemberOf('CAB Approval');



find_real_file.png




find_real_file.png



2) Use this Scratchpad Value in your Client Script as below:



Script:



function onLoad() {


var sections = g_form.getSectionNames();


if (g_scratchpad.grp == 'true')


{


g_form.setSectionDisplay('related_records',true);


}


else{


g_form.setSectionDisplay('related_records',false);


}


}




Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke