Exclude members of a group from User Criteria

LRhodes
Tera Guru

Hi all,

We have a category on our Service Portal which uses a User Criteria to ensure it is not available to users of a certain Company. However we have a need to update this criteria to exclude users that are in this Company but are also members of a certain user group.

 

I have tried to add a script to the User Criteria to check the current users group and return as false if they're a member of the group but as you can guess this doesn't seem to be working. Is my script sound or is it a limitation that I wont be able to work around?

 

1.png

 

function checkGroup() {
    var retVal;
	var currentUser = gs.getUser();
	
	if (currentUser.isMemberOf("Tech IAM team")) {
			retVal == false;
			
		}else{
			retVal == true;
		}
	
	return retVal;
	
}
checkGroup();

 

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hi @LRhodes ,

 

The issue with your script is that you are not assigning the boolean value to the retVal variable properly. Instead of using == (which is a comparison operator), you should use = (which is an assignment operator) to assign the boolean value to retVal. Also, you need to use var when declaring retVal in the function so that it is properly scoped within the function.

Here's an updated version of your script:

 

function checkGroup() {
    var retVal;
    var currentUser = gs.getUser();

    if (currentUser.isMemberOf("Tech IAM team")) {
        retVal = false;
    } else {
        retVal = true;
    }

    return retVal;
}

checkGroup();

 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

Thanks Ratnakar,

 

That makes sense regarding the script - I have updated it accordingly however I'm not seeing the results I had expected. I'll go back to see if perhaps the data I'm using for the group is incorrect - however I was wondering if you would have any understanding that if the user matches with one of the companies I have blanked out in my original screenshot it will match regardless of what the result of the script is?