The CreatorCon Call for Content is officially open! Get started here.

Business rule to check if person is part of multiple groups ?

SandyL83
Tera Guru

Hello,

I need to restrict visibility of Tests within the Test 2.0 module based on the group or groups a person is in..

So my code is below - if they are part of Test Mangement Testers group, they can see tests where product contains EBS. 

The problem I have is if they are part of both Test Management Testers and ServiceNow Tester group, they can't see any tests; and they should be able to see both EBS and NOW tests...

 

Any idea what I'm doing wrong? 

 

if (gs.getUser().isMemberOf('Test Management Testers')) {

 

        current.addEncodedQuery('u_productLIKEEBS');

    

 

    } else if (gs.getUser().isMemberOf('ServiceNow Tester')) {

 

        current.addEncodedQuery('u_productLIKENOW');

 

    }

 

    else if (gs.getUser().isMemberOf('EnergyGas Tester')) {

        current.addEncodedQuery('u_productLIKEENERGYGAS');

    }

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@SandyL83 

this script will give you the count of groups where logged in user belongs to

update your logic

var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());

var length = groups.length;

if(length > 1){
	// user is member of more than 1 group
}

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

SandyL83
Tera Guru

Thank you @Ankur Bawiskar , I appreciate your response! in regard to the new script you just included, do I just add this to the script I currently have? I am not sure where to add this. Thanks agian 

@SandyL83 

yes you need to enhance your BR logic by using script I shared

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