How do I hide a related list TAB in case the user is not a member of a specific assignment group?

Community Alums
Not applicable

Hello Community,

I have found various articles about how to hide a related list under some conditions, but did not find anything helpful about how to hide ONE tab from a related list, in case the logged in user is NOT a member of a specific assignment group:

empty.png

The idea of our architect is to do this with a UI policy, which I scripted like this:

 

 

 

function onCondition() {
    //get the sys property of the specific assignment group
    var portfolioGroup = gs.getProperty('ppm.portfolio.group');

    //get the logged-in user's user ID	
    var userId = gs.getUserID();

    //c
    var isMember = false;
    var groupMember = new GlideRecord('sys_user_grmember');
    groupMember.addQuery('user', userId);
    groupMember.addQuery('group', portfolioGroup);
    groupMember.query();

    if (groupMember.next()) {
        isMember = true;
    }

//name of the project budget tab
    var projectBudgetTab = 'project_funding';

    g_form.setSectionDisplay(projectBudgetTab, isMember);

}

 

 

Then I set the UI Policy Related List Action like:

project_funding.task     visible: True

 

Can someone give me advice please?

2 REPLIES 2

Peter Bodelier
Giga Sage

Hi @Community Alums,

 

Try this in an onLoad client script:

 

 

function onLoad() {
    //get the sys property of the specific assignment group
    var portfolioGroup = gs.getProperty('ppm.portfolio.group');
	//name of the project budget tab
    var projectBudgetTab = 'project_funding';
	
    //get the logged-in user's user ID	
    var userId = gs.getUserID();
	
    //c
    var isMember = false;
    var groupMember = new GlideRecord('sys_user_grmember');
    groupMember.addQuery('user', userId);
    groupMember.addQuery('group', portfolioGroup);
    groupMember.query();
	
    if (groupMember.next()) {
        isMember = true;
		g_form.showRelatedList(projectBudgetTab);
		
	}
	else{
		g_form.hideRelatedList(projectBudgetTab);
	}
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Eswar Chappa
Mega Sage
Mega Sage

Hi @Community Alums  You can achieve it with a Onload Client Script by calling Group validation from Script include as Below:

EswarChappa_1-1695396393533.png

 

 

ClientScript:

function onLoad() {

    var ga = new GlideAjax('checkGroupMember'); // Script Include Name here
    ga.addParam('sysparm_name', 'checkGroup'); // Your Function Name here
    ga.getXML(valdiateGroup);

    function valdiateGroup(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(typeof answer);
        if (answer == 'false') {
            g_form.hideRelatedList('incident.parent_incident');

        }
    }

}

Script Include:

var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	checkGroup : function(){
		var grp = gs.getUser().isMemberOf('477a05d153013010b846ddeeff7b1225');
		return grp;
	},

    type: 'checkGroupMember'
});

 

 

EswarChappa_0-1695396358232.png

 I had tested the above in my PDI with the Exact configuration it was working

 Before User is not a member of the Group:

EswarChappa_2-1695396691942.png

EswarChappa_3-1695396712120.png

 After adding the member to the Group:

EswarChappa_4-1695396806686.png

EswarChappa_5-1695396832749.png

You can observe that Child Incident Related List Hidden in Case-1 was shown after adding the Group in Case-2

Thanks & Regards,

Eswar Chappa

Mark my answer correct and Helpful if this helps you ðŸ˜€