based on the group member hide the sections

Siva82
Tera Expert

Hi Team

 

need to hide certain sections for three different groups of users, which are determined by system properties.

To achieve this, I will write an onload client script and a display business rule. The sections should be hidden based on the logged-in user.

 

Client script

 

function onLoad() [

 

//Type appropriate comment here, and begin script below

 

//// var sec=gform.getSections();

 

var grpmember = g scratchpad.hideSections;

 

if (grpmember) [

 

var grpArr = grpmember.split(",");

 

if (grpArr.includes(g scratchpad.groupvertical)) (

 

g_form.setSectionDisplay('executive_notification', false);

}

}

}

 

Business rule

 

(function executeRule(current, previous /null when async*/) {

 

// Add your code here

 

g scratchpad.hideSections = gs.getProperty('xoc.incident.show_exec_notification');

 

g.scratchpad.groupvertical = current.assignment_group.parent.getDisplayValue():

 

}(current, previous);

 

system property with group names: XOC-NED,XOC-WSt

 

But still not working as expected. Could you please me on this issue

 

Thank you in advance

Siva

1 ACCEPTED SOLUTION

@Siva82 

are you saying if logged in user is member of any of those 3 groups then hide the section?

OR

are you saying if the form has any 1 of those 3 groups then hide the section?

I assume you are talking about the 1st case. If yes then this will work

(function executeRule(current, previous /null when async*/) {

// Add your code here
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", gs.getUserID());
gr.addQuery("group.sys_id", "IN", gs.getProperty('xoc.incident.show_exec_notification'));
gr.setLimit(1);
gr.query();
g_scratchpad.isMember = gr.hasNext().toString();

}(current, previous);

onLoad client script

function onLoad() {
    if (g_scratchpad.isMember == 'true')
        g_form.setSectionDisplay('executive_notification', false);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Siva82 

what's being stored in this property ->

xoc.incident.show_exec_notification

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thank you for your quick reply. We have stored group names that system property

 

Thank you

Siva

@Siva82 

are you saying if logged in user is member of any of those 3 groups then hide the section?

OR

are you saying if the form has any 1 of those 3 groups then hide the section?

I assume you are talking about the 1st case. If yes then this will work

(function executeRule(current, previous /null when async*/) {

// Add your code here
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", gs.getUserID());
gr.addQuery("group.sys_id", "IN", gs.getProperty('xoc.incident.show_exec_notification'));
gr.setLimit(1);
gr.query();
g_scratchpad.isMember = gr.hasNext().toString();

}(current, previous);

onLoad client script

function onLoad() {
    if (g_scratchpad.isMember == 'true')
        g_form.setSectionDisplay('executive_notification', false);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

Thank you for the quick solution.Its working fine