Hiding Form Sections Based on User Group

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 09:52 AM
I am trying to hide a form section based on a users group, which is not listed on the form itself.
I tried the following client script and it's doesn't hide the tab.
function on Load(){
var me = g_user.userID();
if (me.isMemberOf('7efcb8956fa21100dd3253eabb3ee40c'){
var sections = g_form.getSections();
sections[3].style.display = 'block';
} else {
sections[3].style.display = 'none';
}
}
Any help as to what I can do to get this to work would be appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2017 03:58 AM
Hi,
Try not to use alerts in between Glide record.
if(ir.next()){
//use your alert here and try.
g_form.setValue('u_comments', "hi shikha");// use single quotes here
sections[1].style.display = 'block';
sections[2].style.display = 'block';
}
Do you have any mandatory field in these two sections?
Thanks,
Vinitha.K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2017 04:12 AM
Hi,
Yes i had a UI policy on comments field in this section, i have deactivated it for now, But still there is some problem.
I have 2 sections on form:
First section gets visible as per below script:
function onLoad() {
var sections = g_form.getSections();
var approvalstatus=g_form.getValue("u_approval_status");
if (g_form.isNewRecord())
{
{sections[1].style.display = 'none';}
{sections[2].style.display = 'none';}
}
else{
var manager=g_form.getValue('u_manager');
var user = g_user.getUserID();
//alert(user);
//alert(manager);
if (approvalstatus=='Pending Approval' && user!=manager)
{
sections[1].style.display = 'none';
sections[2].style.display = 'none';
}
else
{
sections[1].style.display = 'block';
sections[2].style.display = 'none';
}
}
}
For second section i was using the below code in this same script after second else: but it was not working.
alert('checking user is member of T&E team');
if (approvalstatus=='Approved' || approvalstatus=='Limit Changed Addressed' || approvalstatus=='Limit Change Finalized' && (person.isMemberOf('T&E Credit Card Team')));
{
{sections[1].style.display = 'block';}
{sections[2].style.display = 'block';}
alert('checking done');
}
Now i used your code as per your suggestion:
function onLoad()
{
if (!g_form.isNewRecord())
{
var sections = g_form.getSections();
//var approvalstatus=g_form.getValue("u_approval_status");
var person = g_user.getUserID();
alert(person);
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', '64ca1638db6e3680130a50a4ce961922');
ir.addQuery('user', person);
ir.query();
if(ir.next()){
g_form.setValue('u_comments', "hi shikha");
sections[1].style.display = 'block';
sections[2].style.display = 'block';
}}}
But it is also not working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2017 04:15 AM
First section gets visible as per below script:
function onLoad() {
var sections = g_form.getSections();
var approvalstatus=g_form.getValue("u_approval_status");
if (g_form.isNewRecord())
{
{sections[1].style.display = 'none';}
{sections[2].style.display = 'none';}
}
else{
var manager=g_form.getValue('u_manager');
var user = g_user.getUserID();
//alert(user);
//alert(manager);
if (approvalstatus=='Pending Approval' && user!=manager)
{
sections[1].style.display = 'none';
sections[2].style.display = 'none';
}
else
{
sections[1].style.display = 'block';
sections[2].style.display = 'none';
}
}
}
Section 2 will be visible if you change it to "block".. TRy and let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2017 04:41 AM
Hi Vinitham,
What you have mentioned is already running.
Problem is in below condition:
For second section i was using the below code in this same script after second else: but it was not working.
alert('checking user is member of T&E team');
if (approvalstatus=='Approved' || approvalstatus=='Limit Changed Addressed' || approvalstatus=='Limit Change Finalized' && (person.isMemberOf('T&E Credit Card Team')));
{
{sections[1].style.display = 'block';}
{sections[2].style.display = 'block';}
alert('checking done');
}
I want to make section 2 visible only after manager has approved the request : that is why i have given condition as f (approvalstatus=='Approved' || approvalstatus=='Limit Changed Addressed' || approvalstatus=='Limit Change Finalized'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2017 04:47 AM
Hi,
approvalstatus=='Approved' || approvalstatus=='Limit Changed Addressed' || approvalstatus=='Limit Change Finalized' - Here, please check whether you use values or display values to check the approval status.
Also, declare and set person variable before the if,else part and check.
Thanks,
VInitha.K