# popMenu PowerTable - pass parameter in function called

**URL:** <https://forum.inductiveautomation.com/t/popmenu-powertable-pass-parameter-in-function-called/29712>\
**Category:** General Discussion\
**Created:** [November 6, 2019, 9:16am UTC](https://forum.inductiveautomation.com/t/popmenu-powertable-pass-parameter-in-function-called/29712 "2019-11-06T09:16:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [November 6, 2019, 9:16am UTC](https://forum.inductiveautomation.com/t/popmenu-powertable-pass-parameter-in-function-called/29712/1 "2019-11-06T09:16:01Z")

</div>

Hi,  
I try to create popup Menu and sub Menu in a “onPopupTrigger” script in a Power Table. I get dynamic user in my submenu depending on row seleted in my power table (a row = a project) and I would like to add a user to the selected project.  
When I click on a user of my sub menu, I would like to pass the username in the function called (addUser).

Is it possible ?

Thanks

My code below :

```auto
import system
	
       def addUser(event,username,id):
		import system
		import sys
		#When selected in user list submenu the function have to get the username
		username= ...

		try:
			user_id=system.db.runPrepQuery("SELECT id FROM ignition_users WHERE username=?",[username],"base_administrateur")[0][0]
		except:
			sys.exit()
		query="INSERT INTO ignition_user_projects (user_id,project_id) VALUES(?,?)"
		system.db.runPrepUpdate(query,[user_id,id],"base_administrateur")
		
		
	
	#Get list of users not added to my project
	id=self.data.getValueAt(self.selectedRow,0) #ID of my project
	query="""SELECT DISTINCT u.username as User FROM ignition_projects p
	JOIN ignition_user_projects up ON p.id=up.project_id
	JOIN ignition_users u ON up.user_id=u.id
	WHERE p.id<>?"""
	ds=system.db.runPrepQuery(query,[id],"base_administrateur")
	users=[]
	usersDef=[]
	for row in ds:
		users.append(row['User'])
		usersDef.append(addUser)
		

	
	#List of usernames not added to my project yet and I would like to
	usersMenu=[users,usersDef]
	
	
	subMenu=[['Add'],[usersMenu]]
	menu = system.gui.createPopupMenu(['Users'],[subMenu])
	menu.show(event)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 6, 2019, 4:27pm UTC](https://forum.inductiveautomation.com/t/popmenu-powertable-pass-parameter-in-function-called/29712/2 "2019-11-06T16:27:20Z")

</div>

I highly recommend [`functools.partial`](https://docs.python.org/2.7/library/functools.html#functools.partial) for function composition like this. Basically, leave `addUser` defined as you have it, then call `partial` to wrap the function with the required arguments for each instance you’re going to add to the popup menu:

```auto
	for row in ds:
		users.append(row['User'])
		usersDef.append(partial(addUser, username=row['User'])

```
