Pass AD List to Shared Script

I am attempting to convert a security login project script that we have to be utilized as a global script with a parameter passed in so it can be shared more easily across projects. It seems like the list of AD groups that I’m trying to pass into the script may not be getting received properly so I’d appreciate any thoughts on this.

Here is a layout of what the shared script definition looks like:

def rolesCheck(groupRoles):
	userRoles =
	userRoles = list(userRoles)
	for i in range(len(groupRoles)-1,-1,-1):
		if any(s.upper() in userRoles for s in groupRoles[i]):
			return i

On a button press we run the script below to switch the system user and pass the AD groups to be checked for:

user = event.source.parent.getComponent('Username').text
password = event.source.parent.getComponent('Password').text
groupRoles = [['AD_GROUP_1'] 

Please edit your post to place the code in a code block. (: Just put triple back-quotes (these: ```) above and below the pasted code (on lines of their own).

Wow that is awesome didn’t realize you could do that! Thanks please let me know if you need anything else to look at this I appreciate it.

I think you’re after something like this.

userSource = 'usersource'
user = 'user'
password = 'password'
groupRoles = [

userRoles =, password, userSource)

i = 0	
for item in groupRoles:
	i += 1
	if item in userRoles: 
		securityLevel = i

print i
print securityLevel
print userRoles
print groupRoles,password)

Your code is pretty much working. I made a few minor changes to make it easier to test, but the logic is basically fine. The main changes I made were to make it a bit more “Pythonic”, ie for i, roles in enumerate(reversed(groupRoles)):

def rolesCheck(groupRoles, userRoles=None):
	if userRoles is None:
		userRoles = list(
	for i, roles in enumerate(reversed(groupRoles)):
		if any(s.upper() in userRoles for s in roles):
#			system.gui.messageBox(str(roles))
			return i
	return -1

# On a button press we run the script below to switch the system user and pass the AD groups to be checked for:

#user = event.source.parent.getComponent('Username').text
#password = event.source.parent.getComponent('Password').text
groupRoles = [['AD_GROUP_1'] 

print rolesCheck(groupRoles, userRoles=['AD_GROUP_4', 'AD_GROUP_1'])

Thanks very much for your help. While trying out the code from PGriffith I was still having a problem so I tried putting in another AD group and that one worked. Upon further inspection from printing the returned user roles I noticed that the one I had been testing with has some under case letters and the code was looking for the uppercase version. So I upper cased the user roles and it worked. Thanks again for your help with this!